Blender imported j3o file returns null for AnimControl, even though it's there

Hi, I have a bit of experience with Java but very limited experience with jMonkeyEngine. I’ve gone through the beginner tutorials, and reluctantly moved from an OO design to a Controller design. But I can’t run animations on my spatial for the life of me. I’ve got a playerControl class now to control the movement and whatnot of my player, and I want that to also handle the animation. So, I have this in the playerControl class constructor, which is already applied to the player spatial:

public PlayerControl(CharacterControl c, Camera cam) {
this.c = c; = cam;
direction = new Vector3f().normalizeLocal();
plrDir = new Quaternion().normalizeLocal();
control = spatial.getControl(AnimControl.class);
channel = control.createChannel();

Boom, NullPointerException. It simply refuses to work, even if I load it from the rootNode instead, in the main class. Here’s the hierarchy of my model, with the AnimControl shown:

I know this has been hashed over before, but none of them have helped me. I would just export the model as an Ogre, but I have issues with that, too. I really just need to figure out how to play the animations. It’s either that or just go back to coding 2d games in Eclipse… :stuck_out_tongue:

Let me know if you need more information.

Which line generates the NPE?
Also, please edit your original post (by appending /edit to the URL) so we can see the tree.

This line throws the exception:

control = spatial.getControl(AnimControl.class);

And here’s the URL fixed:

@MisterOorngh said: This line throws the exception:

control = spatial.getControl(AnimControl.class);

And here’s the URL fixed:

No… you’ve just posted an image directly from your hard drive or something. You need to upload it somewhere. is great for this.

If you’re in a custom control and the spatial field is null, that suggests that the control has not been added to any spatial yet. See the Javadoc for Spatial.addControl().

Okay, that should be right…

No, it’s added in my main class. I load the spatial in a void that is called above, then apply it here:

PlayerControl plrCont = new PlayerControl(player.getControl(CharacterControl.class), cam);


Yeah, if I’m making the controller before I apply it to the spatial, duh the spatial is null in the constructor.


No good. Now I made a private void animInit() and called it in the update loop instead (all in the controller class), in this line:

if(spatial != null)

Now I’m getting an exception at the same line, now it’s just moved to the animInit() void. Ugh…

The Spatial you’re applying getControl() to, is it rhino or rhinoSkeleton or rhino.blend?

I’m not sure, to be completely honest. Like I said, I’m very new to this engine. I can tell you, though, my rhino model is imported from a .blend file via the import button on the SDK. The file then, of course, is a j3o. Then I set a Spatial equal to:

player = assetManager.loadModel(“Models/ent/player.j3o”);

That spatial is what I apply the control to. So, I think, yeah, it’s the blend file. Would it help if I put the whole code here so you could see? I know I’m jacking something up, I just came here because I have no idea what it is.

The control is on the sub-node, just look at the image yourself… This code is available in the forum about a hundred times but I post it again just for you:

[java]Node model = (Node)assetManager.loadModel(myModel);
Spatial subNodeWithTheControl = model.getChild(“rhino”);
AnimControl control = subNodeWithTheControl.getControl(AnimControl.class);[/java]

1 Like

Thanks! I ran it through like you said, and it worked great. Thanks for bearing with me through all of my noob mistakes. You’ve all been such a great help!

One last question: Is there any way I could run through my animInit method in the controller only once without making a new variable? Because it yelled at me that I added the actionListener already, and since the spatial isn’t null all throughout the runtime that method is being called again. I know I could use a Boolean and fix it, but perhaps there is a better way?

1 Like

Override setSpatial()? (just make sure to call super.setSpatial())

Okay, thanks!

By the way, if a particular forum post is helpful to you, you should rate it accordingly by clicking on the “thumbs up” icon.