Hey guys,
I’m using AnimationController on a Zombie model, which works great for Looping animations.
Today I implemented Attack animations, where Looping is False.
I subscribe to E_ANIMATIONFINISHED in order to receive notification that we’ve reached the end of a non-looping animation, and in the handler for that event, I Unsubscribe from it.
All good so far, except that after a few attacks, my Zombie fails to receive that important event, and so it just stands there looking stupidly at my player.
I can trigger further attacks by moving the player away from the zombie, but what I really would like to know, is why my code is not reliably receiving the event in question!
        }else
        {
            if(okToAttack_)
            {
                /// Choose a random attack
                int rand=Rand();
                float frand = (float)rand / 32768.0f;
                frand *=3; // zombies have three attacks
                int irand = (int)frand;
                /// Play attack animation - looping is FALSE
                animCtrl->PlayExclusive(Animations_[Animations_Zombie::Z_Attack + irand].Name, 0, false, 0.2f);
                /// During attack, it is not ok to attack again
                okToAttack_=false;
                /// We need to be notified when the attack animation has finished
                SubscribeToEvent( GetNode()->GetChild("Adjustment"), E_ANIMATIONFINISHED, URHO3D_HANDLER(Character, HandleAnimationFinished));
            }
        }
    }
}
void Character::HandleAnimationFinished(StringHash eventType, VariantMap& eventData){
    /// Attack animation has finished - we can stop listening for this event
    UnsubscribeFromEvent(GetNode()->GetChild("Adjustment"), E_ANIMATIONFINISHED);
    /// Zombie is now free to attack again
    okToAttack_=true;
}EDIT:
I have discovered that this bug only occurs when the same non-looping animation is executed twice in a row. AnimationController thinks it has already sent the event once, and so never sends it again, unless a different animation is played. Sure I could keep track of which attack was used last and make sure never to use the same attack twice in a row, and that’s fine for my zombie, but it’s a big problem for my player character, we have to assume that the player will repeatedly apply the same attack, so short of monitoring the state of the non-looping animation, I’m out of luck! Has anyone else run into this issue? What was your workaround?
Calling Stop on the previously-played animation did not fix it, the only thing that has worked for me is calling SetTime on the previous animation, and passing in zero as the time.
 
         
         
         
         
        