- Home /
Animation Event in state machine state
I have a simple Finite State Machine which i use, along with states, to control my enemy characters who currently have working states for Idle, Hunting and Attack (based on this tutorial: https://learn.unity.com/tutorial/finite-state-machines) This works great so far.
I have now added an AnimationEvent in the Attack animation, however as its only StateMachine itself which is attached to the enemy GameObject, not the individual states (as this are instantiated by the StateMachine) I cannot attach this Event to the Attack state. Only functions within the StateMachine.
I currently work around this by implementing the attack within the StateMachine, to prove it works. But I would like to keep my code clean and modular, so any suggestions how I can get my attack implementation into the attack state class and still be accessible from the AnimationEvent? Could this be done with a Delegate maybe?
Your answer
![](https://koobas.hobune.stream/wayback/20220613005506im_/https://answers.unity.com/themes/thub/images/avi.jpg)