Search code examples
c#unity-game-enginegameobject

Unity Events from Animations are not getting triggered


I'm using an Animator to animate the player, and an Animation Blend to transition from different walking animations. Now, I wanted to add walking SFX to the player. I saw ressources online about the Animations Events, so I tried to implement them. Now the thing is, the events are not getting triggered, and I don't understand why.

So, my player looks like this :

The Player's GameObject

And here is the PlayerModel, containing the script for the SFX :

The PlayerModel Inspector

The AnimationEvent looks like this for every animation (I doubled checked typos and such) :

The AnimationEvent

And the script (so the script you see on the PlayerModel) contains this function :

public class PlayerWalkSFX : MonoBehaviour
{
    [SerializeField] private AudioSource playerWalkAudioSource;
    [SerializeField] private AudioClip[] carpetStepClips = default;

    public void Step()
    {
        Debug.Log("Get called");

        playerWalkAudioSource.PlayOneShot(GetRandomAudioClip());
    }

    private AudioClip GetRandomAudioClip()
    {
        return carpetStepClips[UnityEngine.Random.Range(0, carpetStepClips.Length)];
    }
}

Now, I've only saw that the script needs to be on the same GameObject, the function properly named and there you go. But they are not triggered, and I don't understand why. If you need more infos, I can send more.


Solution

  • So if someone stumbles upon this post, just know that I asked to devs IRL too, and they checked my project. There was no solution, since the problem was impossible to understand, and they had the same years prior. They simply stopped using it.