Custom Model Crash

I get this crash message whenever I try to create a spatial and add the animation channel and control and the AnimListener

 SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
 java.lang.NullPointerException
at mygame.Main.simpleInitApp(Main.java:48)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:226)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:744)

line 48 is just say control.addListener(this).

Can someone tell me why this happens

Also the file I imported is a .j3o file

this is the code:

player =  assetManager.loadModel("Models/STP-49/STP-49.j3o");
player.setLocalScale(0.5f);
rootNode.attachChild(player);
control = player.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
channel.setAnim("Reload");

Aslo sorry if this question is really simple, I’m just starting to animate

Player does not have an AnimControl. It could be in one of the children. Look at the model in the scene explorer to see.

wut?

can you explain a bit more I don’t really understand what you mean by “Other Children”, also how do you look in the scene explorer to find other children?

Player is also a Spatial by the way

And Spatial is a superclass of Node and Geometry. Yours is a Node… and it has children.

I’m not sure how better to explain “open it in scene explorer” but here goes.

Make sure you have the SDK open.
Expand your project tree on the left. It’s the tree view that has projecty things in it and looks kind of like the tree view in windows file explorer. In IDEs, this is where it shows your project and stuff.
Find the assets folder under your project.
Expand the project assets folder by clicking on the little +/- button.
Expand the models folder by clicking on the little +/- button.
Do you see your model file in there?
In Windows, right clicking on an object will often open up a menu with additional options that one might perform on that object.
Right click on your model file.
There should be an “Edit in SceneComposer” option. Click that.
Your model hierarchy will be displayed in the lower left panel… it’s another tree-like view where you can click to expand the tree sections.

You can use this to figure out which child has your control.

2 Likes

I can’t really see which child to choose
Here is what I have in my scenecomposer tree.

Also what would the code look like, thanks

by the way, sorry for asking so many questions.

Following the scene composer tree what you need is “Armature” as it is the one containing the control. To explain that in other word, the player you are loading is a node containing multiple child and one of these child contain the control you need, the child named “Armature” in you case.
So to get you control you need to to edit the line where you request the control as :

control = player.getChild("Armature").getControl(AnimControl.class);

great! It works however it tells me that it cannot find the animation name… (I tried to use “Reload”)

Armature’s AnimControl has only “Scope” animation. “Reload” is on Armature.Cube node’s AnimControl.

1 Like

You need the “Cube1” child, NOT “Armature”.