How does animation switching work?


I am able to do animation but the problem I have is switching. If I use PlayExclusive. It tends to lose the animation and if I use Play the animation doesn’t repeat I thought maybe it is the weight but it’s not the case. I seems maybe I have the animations on the same layer and Urho3D might be getting confused.

I’m not sure.


AnimatedModel* objectNodemodel=objectNode->CreateComponent();

/// Add Animation Controller

/// Setup mesh and mesh details nodes and stactic models
       ///       Code for character 

    /// Add animation state
    Animation * IdleAnimation = new Animation(context_);
    IdleAnimation = cache->GetResource<Animation>("Resources/Models/standardbipedolianfemaleIdleAction.ani");

    objectNodemodel -> AddAnimationState(IdleAnimation);
    IdleAnimation -> SetAnimationName ("IdleAnimation");

    /// Add Walking Animation
    Animation * AddAnimation = new Animation(context_);
    AddAnimation = cache->GetResource<Animation>("Resources/Models/standardbipedolianFemaleWalkAction.ani");

    objectNodemodel -> AddAnimationState(AddAnimation);
    AddAnimation -> SetAnimationName ("WalkAnimation");

    /// Get Controller
    AnimationController * playermeshAnimationController1 = objectNode -> GetComponent<AnimationController>();

    /// Set Morph Weight
    playermeshAnimationController1-> SetWeight("IdleAnimation",1);
    playermeshAnimationController1-> SetTime("IdleAnimation",1.89753);

    playermeshAnimationController1-> SetWeight("WalkAnimation",1);
    playermeshAnimationController1-> SetTime("WalkAnimation",2.45833);


Code in FixedUpdate

[code] // Movement in four directions

  /// code for controls

    /// If in air, allow control, but slower than when on ground
    body->ApplyImpulse(rot * moveDir * (softGrounded ? MOVE_FORCE : INAIR_MOVE_FORCE));

    animCtrl -> StopAll();

    animCtrl -> PlayExclusive("WalkAnimation", 0, true, 0);

            animCtrl -> PlayExclusive("IdleAnimation", 0, true, 0);

i’m do not use the AnimationController yet
but i guess that the play function need full path to ani file … oller.html


for anim states (i usually use they with own FSM construction):
set to IdleAnimation state lower priority layer (0). SetWeight(1.0f) - always. prevState = CharacterState and now CharacterState = IDLE
set to walkAnimation state high priority layer(1) 0+1. SetWeight(1.0f) - only then you press WASD buttons(or you also may add fadeWeight for few sec). prevState = CharacterState and now CharacterState = WALK

in update (timeStep)
//STAGE1. clear prev states
if (preState == WALK)
walkAnimation. SetWeight(0);
else if (preState == IDLE)
// do not needed to reset anything this state are default for play
else if (…)


//STAGE2. anim current selected state
if ( CharacterState == IDLE)
IdleAnimation. SetWeight(1.0f);
else if (CharacterState == WALK)
walkAnimation. SetWeight(1.0f);

more complex example how i switch animStates … BigBot.cpp

Maybe you should use a fadeTime different than zero and not use weights.

[quote=“codingmonkey”]i’m do not use the AnimationController yet
but i guess that the play function need full path to ani file … oller.html

I went to the state changing method directly. I tried AnimationController but once that I read that it deletes animations. It couldn’t be used because I preload the animations with the character.

Unless there was a flag or function to tell AnimationController not to delete I’ll do the animation switching directly. Maybe copy AnimationController and modify so it was it doesn’t delete preloaded animations to make life easier.

I updated Git with the rough animations added.