unity-game-engine

Unity 6 - Animation clips causing player to not be able to move


I made some extra animation clips and their mere existence causes the player not to be able to move. I don't know why, when I delete the new animation clips I can move the player again. I tried undoing code to see if it was the code, but it wasn't.


Solution

  • As soon as an animation that exists in the AnimatorController holds any keyframe on a property - even if that clip/state is not being currently played - this property is basically locked / owned by the Animator so you can't overwrite it from script.

    One way would be to set things in LateUpdate or using WaitForEndOfFrame as this is executed after the animation update loop. Both is pretty dirty as it basically "fights" against the Animator and overwrites the values after Animator has already set them => You can't rely on e.g. incremental movement as in the meantime the Animator might already have reset the property.

    The alternative is to use a base AnimatorController that does NOT have your new AnimationClips which animate the position but only the according states.

    And then only while those clips are needed and the object is rather supposed to be moved by the animation then use an AnimatorOverwriteController which only then has the according animations.


    Otherwise as mentioned you can also nest the player under another root object, move the root by script and only animate the player relative to that root object.