- Home /
Animator override script is not entirely read
I have several enemies and I want to make only one animator for all of them. So, the animator need to be overridden for each enemy. I have done this script:
public class EnemyAnimation : MonoBehaviour
{
public AnimationClip[] animationClips;
private Animator animator;
private AnimatorOverrideController animatorOverrideController;
public void Start()
{
animator = gameObject.GetComponent<Animator>();
animatorOverrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
animatorOverrideController["Move"] = animationClips[0];
animatorOverrideController["Move_Right"] = animationClips[1];
animatorOverrideController["Move_Low"] = animationClips[2];
animatorOverrideController["Move_Left"] = animationClips[3];
animatorOverrideController["Attack"] = animationClips[4];
animatorOverrideController["Death"] = animationClips[5];
animator.runtimeAnimatorController = animatorOverrideController;
}
}
The issue is that the last line is never reached. Sometimes the code stop at the line of ["Move"], sometimes at the line of ["Death"]. This is not due to an error of compilation or others. It's just that the other line are not reached because the Start() method of another enemy's EnemyAnimation begins and is read. Where could the origin of the problem ?
Your answer
Follow this Question
Related Questions
How to properly detect the end time of an Animation which wait for the end of the previous one ? 1 Answer
How to use Animator Override Controler in script? 0 Answers
Parent animator controller overrides child's animations 1 Answer
How to create animations that can be edited with scripts in runtime? 1 Answer