RuntimeAnimatorController newAnimController = Resources.Load(“AnimControllers/WalkAnimatorController”) as RuntimeAnimatorController;
void changeAnimatorController()
{
this.gameObject.GetComponent<Animator>().runtimeAnimatorController = newAnimController ;
}
Now calling this function is working differently when called in the following two different ways:
1.If I call the function ‘changeAnimatorController’ directly from script, my Animator controller is getting updated to the new one, but gameObject’s position is getting changed to the gameObject’s original position present before the game play starts, and getting updated to the correct position in next frame.
2.If I call the function ‘changeAnimatorController’ from an event of animation clip present in current animator controller (which I am going to replace), gameObject’s position is getting changed to the gameObject’s original position present before the game play starts, and never getting updated to the correct value in any frame.
In the above two cases, after changing RunTimeAnimatorController of gameObject, rotation of gameObject is getting changed to gameObject’s original rotation present before game play starts.
Any idea why it’s happening this way? Why calling the function ‘changeAnimatorController’ from different places works differently?