How to implemet animation for any Moving Spatial or Object

I have implemented Animation Channel with one AnimControl
Now , when i run my program i get a NullPointerException as if i havenot initialized the Object Anim Channel or Anim Control… Any Suggestions ?
Thank you,


AnimControl control = spaceship.getControl(AnimControl.class);
              System.out.println(control);//it gives me null in stackTrace
                 channel = control.createChannel();

in simpleInitApp();


 if (KeysListener.up) {
                    channel.setAnim("Up", 1.3f);
                    rotateShip(spaceship, walkDirection, new Vector3f(0f,cam.getRotation().getY(),0f));

in simpleUpdate(float tpf);

If control is null then spaceship doesn’t have an AnimControl.

1 Like
1 Like

Or it’s on a child… or…

Could be three or four things. Need more information to know what.

1 Like

Actually , yes it doesnot have ,but i didnot find how to create one for a spatial or node in JmE wiki

It’s hard to answer questions unasked, unfortunately. Then we play 20 questions.

What are you actually trying to do?
What have your tried?

1 Like

I have tried snippets of what i have sent here which is the same as JME wiki, but they seem they are not complete code because i cannot find resource …i have read examples & wiki

What are you actually trying to do?

As in, what do you want to accomplish? What are you starting with? Where does spaceship come from?

Actually… I’m out. I’ll let other people play the game. I will say that not once in the entire history of JME questions has anyone ever complained that OP provided too much information. So if you are going to err in one direction or another: provide way more information than you right now think is required.

I just want to assign an AnimControl to a spatial or Node

That’s easy.
mySpatial.addControl(new AnimControl());

…but probably, and I’m just going out on a limb here… you actually want to DO something with it.

Because just adding an anim control to a node or spatial is going to have an empty anim control, no skeleton, etc…

And now we are right back to what are you ACTUALLY trying to do? “Having a control on the spatial” is not your end goal. Else you can do that in one line above and be done.

all i understand is that you get NullPointer about something animation related(i noticed now you have it on control variable), but you didnt provide full stacktrace.

i can only guess your issue now.

you probably have AnimComposer instead of AnimControl classes due to 3.3 changes.

or you have no animations exported with model.

Still, like people said above, it lack information to help u.

informations that could help help u.:

  • how do you export spaceship(where it get from like pspeed already asked)
    its important, because this control is get from export usually.

  • are you sure model have animations in source in it?

  • what JME version model was exported/created and what JME version you use to load it.

1 Like