I wanted to use animation events to make my character eat. I would do this by making the food dissapear at the middle point of the animation and that making the anim bool false at the end of it
The method looks fine. Is the script on the same game object as the Animator? Only methods in scripts on the same game object qualify for animation events. I often make small helper scripts that contain the animation event and then forward it to where I need it to go to work around this, if the script and Animator are on different game objects.
Also, rather than entering the name by hand, it’s better to select the game object with the Animator containing the Animation Clip in the scene and then open the clip / select the animation event. Instead of a text field, you’ll then get a drop down with all the available methods on all the scripts on the same game object as the animator. This prevents typos and immediately makes it clear if you forgot to add a script or the method signature is not compatible.
I have multiple gameobject that can play this animation so do I need to put everyone of them a script ? Or can I put it on a parent game object that holds all of them.
I remember finding something like this in my earlier projects but now i cant find it even with the way you told me. Is there a way you can show me how to access this menu ? Or tell me more clearly how to open it ?
It needs to be the same game object as the Animator, it cannot be on a parent or child. So you’ll have to put a script on every game object with an Animator that plays clips with events.
It’s the same inspector you’ve posted a screenshot of, where you can enter the animation event name and parameters. This inspector can look different depending on the context. To get the dropdown menu in the inspector when selecting an animation event, these conditions have to be met:
You have to have a scene game object selected that has an animator component
The animator component needs to have a controller that contains the animation clip you’re editing
Maybe the easiest is to first open the animation clip, select the Animator in the scene, switch back to the animation window and select an animation event. Then the inspector should show only a dropdown menu.