Hello everyone,
I would like to detect the end of attack animation.
First of all, I tried to use Animation Events but they don’t work (sometimes when animation was very fast the event was not triggered).
I decided to create a custom method for detect an animation changed :
private void CheckEndOfAnimation()
{
var state = CharAnimator.GetCurrentAnimatorStateInfo(0);
if (Attacking)
{
if (!_checkEndAnim)
{
if (_currentAttackState != state.nameHash)
{
_currentAttackState = state.nameHash;
_checkEndAnim = true;
}
}
else
{
if (_currentAttackState == state.nameHash)
{
if (state.normalizedTime >= 0.99f && !CharAnimator.IsInTransition(0))
{
if (_currentAttackTrail != null)
{
_currentAttackTrail.transform.parent = null;
}
Attacking = false;
_checkEndAnim = false;
}
}
else
{
if (_currentAttackTrail != null)
{
_currentAttackTrail.transform.parent = null;
}
Attacking = false;
_checkEndAnim = false;
}
}
}
else
{
_currentAttackState = state.nameHash;
}
}
It seems to work for most cases… but sometimes “state” variable (CharAnimator.GetCurrentAnimatorStateInfo(0)) change in the middle of an animation (without reason).
For debug this problem, I would like to know what is the new animation… but i can’t get the state name.
I tried to instantiate (in Start method) a dictionnary with state name and hash ids for i can’t get the hash (wich is in substate system).
// Works
AnimHashes.Add(Animator.StringToHash("Base.Idle"), "Idle");
// Doesn't work
AnimHashes.Add(Animator.StringToHash("Base.RightWeakAttack2"), "RightWeakAttack2");
AnimHashes.Add(Animator.StringToHash("Base.Attacks.WeakAttack.RightWeakAttack2"), "RightWeakAttack2_TEST");
Thanks for your help,
Best regards.