Search Unity

Question The animator won't play state immediatly in the same frame where I enable gameObject

Discussion in 'Animation' started by ctxmaps, Dec 19, 2023.

  1. ctxmaps

    ctxmaps

    Joined:
    Oct 11, 2022
    Posts:
    3
    When I activate a gameobject and then play animation like this:

    gameObject.SetActive( true );
    animator.Play( "Test", 0, 0f );
    animator.Update( 0f );
    Debug.Log( "play animation" );


    The animation won't play immediatly in this exact frame. For a moment, I can see initial object position (for 1 frame) and then my animation starts playing.
    Frame-by-frame shows that animator state is NOT set to "Test" in this exact frame, but Debug.Log prints normally, so animator.Play was executed.

    animator.Update() makes no effect
    animator.Rebind() makes no effect
    (I've tried many combinations to call these before or after, still no effect)

    Is there anything I'm doing wrong here? Or it is expected behaviour?
    The only workaround I see is to enable "renderer" to make object visible with 1-frame delay, but that's not okay!