Blend Tree Fire all Animation Events from all Animations at same time

Hi,

I’m having an issue with Blend Tree and Animation Event.
When I trigger a parameter (MeleeFight), Animator enters in a Blend Tree and Blend Tree choose the right Animation to play with 2D Simple Directional. Each Fight Animation has an Animation Event at beginning and calls a function with a specific Integer parameter. It works with my Hero, only Animation Event from Animation that Blend Tree is choosing is called. But with my AI Enemies, all Animation Event from all Direction Animations are called…

How is it possible?

Thank you for any answer :slight_smile:

Here is a Screenshot of my Blend Tree :

I found on another Thread that it’s a normal thing from Blend Tree to call Animation Events from all Animations.

To resolve it, I need to verify the weight of the Animation that called function. Here is the solution :

I figured it out, it’s because of the blend tree’s trigger condition is blurry, so we can manually transfer your moveX, moveY into 1 or 0 instead of those specific float number, according to the angle of your direction Vector2

Take my topdown 2d 8 direction game’s enemy logic as sample, 22.5 = 360 / 8 / 2, you can also refine these conditions through variable definition & calculation:

public Vector2 getFinalAnimFloat(Vector2 oldDir)
{
    float signedAngle = Vector2.SignedAngle(new Vector2(1, 0), oldDir);
    if (signedAngle >= -22.5 && signedAngle <= 22.5)
    {
        return new Vector2(1, 0);
    }
    else if (signedAngle >= 22.5 && signedAngle <= 67.5)
    {
        return new Vector2(1, 1);
    }
    else if (signedAngle >= 67.5 && signedAngle <= 112.5)
    {
        return new Vector2(0, 1);
    }
    else if (signedAngle >= 112.5 && signedAngle <= 157.5)
    {
        return new Vector2(-1, 1);
    }
    else if (signedAngle >= 157.5 || signedAngle <= -157.5)
    {
        return new Vector2(-1, 0);
    }
    else if (signedAngle >= -67.5 && signedAngle <= -22.5)
    {
        return new Vector2(1, -1);
    }
    else if (signedAngle >= -112.5 && signedAngle <= -67.5)
    {
        return new Vector2(0, -1);
    }
    else if (signedAngle >= -157.5 && signedAngle <= -112.5)
    {
        return new Vector2(-1, -1);
    }
    else return Vector2.zero;
}

then:

public void SetAnimation(string animationName, Vector2 dir)
{
    Vector2 finalDir = getFinalAnimFloat(dir);
    anim.SetFloat("moveX", finalDir.x);
    anim.SetFloat("moveY", finalDir.y);
    anim.Play(animationName);
}