- Home /
Checking if animator has an animation state or event key?
I'd like to know if there's any way to check if an animator has a state or event key through c# script.
Currently, we are using EventKeys to transfer important data between to player characters using an execute() function. For example, an Attack animation will have a specific EventKey (timestamp) in which it will hurt the enemy player and inform the player's character to play the hurt animation. We do it this way because hitboxes are unimportant for the game we are developing (think turn based mechanics, or the like) but would still like the character data to update at the appropriate time. This means our execute() function is reliant on both having an animation and having an event key in that animation that calls the execute function.
To prevent errors, I would like to be able to check if the animator has the desired animation and if that desired animation has an event key which calls "execute". If it doesn't, I would then manually call execute myself, thus removing any chance for the client to inappropriately set an animation without an event key (which would cause the game logic to lock-up.)
Can this be done? Should I be doing this in a different way?
Your answer
![](https://koobas.hobune.stream/wayback/20220613150230im_/https://answers.unity.com/themes/thub/images/avi.jpg)