Module animation not playing

Hi all,

I’m doing a test where I’m trying to load and play animations on an actor from a c++ function that is called in python as a module. While everything appears to be loaded properly, the animation does not play or loop when prompted. Here’s the c++:

class mainGameLoopA{
PUBLISHED:
    void test_loading_model_and_actor(NodePath sent_render)
    {
        Loader* loader = Loader::get_global_ptr();
        // Load a model synchronously
        PT(PandaNode) model_node = loader->load_sync("./samples/roaming-ralph/models/ralph");
        NodePath actor(model_node);
        actor.reparent_to(sent_render);
        PT(PandaNode) anim_node = loader->load_sync("./samples/roaming-ralph/models/ralph-walk");

        NodePath anim_np(anim_node);
        anim_np.reparent_to(actor);

        AnimControlCollection anim_controls;
        auto_bind(model_node, anim_controls);

        string loaded_anim;
        cout<<"anims: "<<anim_controls.get_num_anims()<<"\n";
        loaded_anim=anim_controls.get_anim_name(0);

        //actor.play(loaded_anim);
        cout<<"ANIM-NAME?: "<<loaded_anim<<"\n";
        anim_controls.loop(loaded_anim, true);
        if(actor.find("**/+Character").is_empty())
            cout<<"EMPTY, NO JOINTS??\n";
        else
            cout<<"NOT EMPTY, HAS JOINTS??\n";
    }
}

And on the python side:

testGMLP=genModule.mainGameLoopA()
testGMLP.test_loading_model_and_actor(render)

What could the problem be? After loading and binding animations, how would I ensure they play when prompted from the python side?

EDIT:
It turns out, I can’t even pose the actor at a certain frame like so:

anim_controls.pose(loaded_anim, sent_frame_pos);

Yet calling this shows that frames indeed have been loaded:

        int num_frames=anim_controls.get_num_frames(loaded_anim);
        cout<<"nf?: "<<num_frames<<"\n";//Output is 25...

So it’s rather confusing. Why isn’t the model being animated or updated at all? Did I bind things incorrectly? Is there something else missing?

Thanks in advance.

So, I seem to have found a quick fix. Making the "AnimControlCollection " object non-local to the function that’s calling it on the c++ side and making the python variable a member of the main class that’s being run on the python side seems to do the trick:

c++:

    AnimControlCollection anim_controls; //<---Put it outside of the function.
    void test_loading_model_and_actor(NodePath sent_render)
    {
     ...
    }

and python:

       self.testGMLP=genModule.mainGameLoopA()#instead of testGMLP=genModule.mainGameLoopA()
       self.testGMLP.test_loading_model_and_actor(render)#instead of testGMLP.test_loading_model_and_actor(render)

After that, I could loop, play and pose the animations as desired. :sweat_smile:

There is no other way to get away from this yet, about it in detail from:

2 Likes

I see, thanks for the relevant information, in any case, at least I have a solid workaround.