[Bug] Timeline Play On Awake does not work properly

In SceneA I have animation in timeline with a play on awake turned on, which moves my gameobjectX out of the screen and slowly brings it back. (Initial position of gameobjectX is in the middle of the screen)

But When I am in SceneB and I load SceneA, there is one frame glitch, where I see my object for a fraction of second in the middle of the screen.

I debugged the position of the object and the timeline moves it on a second frame but not in the expected Awake method.

Why is that?

This is also very bad when I set up an activation clip starting in the middle of the timeline(That means at the first half of the timeline the object is deactivated), but when I run a timeline with turn on awake on. My Gameobject on the first frame is still activated (so all the onStart, Awake, onEnable methods are triggered ), and only after that inside the second frame it turns of. But I want this game object to be inactive from beginning exactly how I am defining it in the timeline. So the timeline should take care of it, that’s how I am expecting it to work

If I recall correctly, PlayOnAwake starts the timeline playing on the next frame because the delta time between the first and second frames can be very long - due to loading, instantiating and other resource work done in Awake(), but some timer modes will cap the delta time to 1/30.

That caused timelines to appear to not start at the beginning, or, if the delta time is capped, for the audio to be wildly out of sync.

In your case, start with the object disabled in the scene. The activation track can be set to enable it on completion (instead of using revert).

Well, that what I wanted not to do because I am losing track of what I have in my scene if I disable everything.
But why it can’t be fixed? inside Timelines awake method you can just check all the clips starting values, and just set them how they are, It doesn’t need to be played right away just set and it will work. It is super bad if I am expecting Timelines start on awake to not start when awake method is trigerred.
It should be called start next frame.

I did forget to mention that timeline (playables) processes between Update() and LateUpdate(), so Awake, Start, OnEnable will be called for anything enabled in the scene .

I’m not sure that the behaviour is broken, actually. If the scene default of a gameObject is ‘on’, then Awake is expected to be called when the scene loads. Timeline should not break that contract.

But you can probably get the behaviour you want with a script that calls playableDirector.Evaluate() in an Awake() method. That will force evaluate the first frame of the timeline.

2 Likes

Amazing that actually works! Thanks a lot.

I don’t think Timeline is breaking the contact, it is basically overriding the behavior because if I am setting the play on awake and I am expecting that everything setup on the timeline will be triggered inside awake method.
So I think playableDirector.Evaluate() should be inside Timelines awake method by default if I press play on awake.

Related:
Timeline Notifications aren't sent in PlayableDirector Manual Mode (general thread on 1-frame lag)
Animation lags by 1 frame when activating object via Timeline signal callback (my own thread, more specifically about animation)

1 Like