- Home /
best practice for synching animator and script
after watching all of the animation tutorials, i ran across a problem when using a script + animator controller. i want to have a c# monobehaviour on my character to control input and handle properties in the script public variables.
but i want to make a function call at the end of an attack animation. this seems to be a common use, but i couldnt find anything on it:
so i want to know when animation states change, which would require a statemachinebehavior. the problem with this one is that i will have to attach it to each animation clip in my animator controller for it to make the correct callbacks to my script which seems quite unpractical. and it would mean each one has to find the Monobehaviour script when instanced (that is how it is described in the documentation to pass calls from statemachinebeh. to monobeh.), which might cause performance issues.
constantly reading the animator controller state and comparing it to the hash values resulted in quite inprecise and creates wrong results as i was trying to reconstruct the animator Controller structure in script. this is really bad when animations are fast (only several frames)
basically, what is the best practice to know in the controlling monobehaviour when an animation state exits?