Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Animation is not playing in editor if root motion handled by script (since 2019.1.2)

Discussion in 'Animation' started by vinchkovsky, May 15, 2019.

  1. vinchkovsky

    vinchkovsky

    Joined:
    Oct 9, 2016
    Posts:
    14
    Hello

    If a script with OnAnimatorMove is attached to object with Animator, I can't see correct position values on timeline, and animation is not playing in the editor. Even with the simplest script and empty OnAnimatorMove:
    Code (CSharp):
    1.  
    2. public class AnimatorMoveTest : MonoBehaviour
    3. {
    4.     protected virtual void OnAnimatorMove() {}
    5. }
    6.  
    How it always looks with script attached (and even not enabled):


    If I remove script, everything is alright:


    Is this an expected behavior? How to handle that? Looks like a critical issue for me.

    Thanks.
     
  2. vinchkovsky

    vinchkovsky

    Joined:
    Oct 9, 2016
    Posts:
    14
    How it was before: Even with script with OnAnimatorMove and ExecuteInEditMode attached, I was able to watch and modify values on timeline. When I was playing timeline, object was moving. When I selected another object, previous one's position was reset.

    How it is now: If script with OnAnimatorMove is attached, I always see just weird value "-1.5259e-05". Playing timeline does nothing. I can move object only if I enable ExecuteInEditMode and apply Animator.deltaPosition. But I don't wan't to permanently move object in OnAnimatorMove just while testing animation; and I'm still unable to see values at timeline.
     
  3. vinchkovsky

    vinchkovsky

    Joined:
    Oct 9, 2016
    Posts:
    14
    Well, I fixed that by introducing ROOT_MOTION_SCRIPT_DISABLED define symbol, and now my OnAnimatorMove events look in such a way:

    Code (CSharp):
    1. #if !ROOT_MOTION_SCRIPT_DISABLED || !UNITY_EDITOR
    2.     void OnAnimatorMove()
    3.     {
    4.     }
    5. #endif
    And I'm adding/removing this define symbol by PlayerSettings.SetScriptingDefineSymbolsForGroup in EditorApplication.playModeStateChanged event.

    So now everything works like before, maybe with some extra loading time when state changes. Hope it will be fixed in Unity as well so there will be no need to use such weird custom fixes.