I’m having some trouble getting the manual update mode working the way I want it to.
I’m trying to have a timeline that animates the transform of several objects. The objects themselves have an Animator Controller, so they already have an animation running ‘locally’, as well as being animated ‘globally’ by the timeline. This works correctly when I set the timeline’s update mode to Game Time & play on awake. So far so good.
Now, for reasons I won’t get into, I want to be able to manually drive the speed at which this timeline plays (instead of using global timeScale), so I added a script to the timeline gameobject with the following:
using UnityEngine;
using UnityEngine.Playables;
public class TimelineVelocityController : MonoBehaviour
{
PlayableDirector timeline;
float velo = 1;
// Start is called before the first frame update
void Awake()
{
timeline = GetComponent<PlayableDirector>();
timeline.initialTime = 0;
timeline.time = 0;
}
// Update is called once per frame
void Update()
{
timeline.time += Time.unscaledDeltaTime * velo;
timeline.DeferredEvaluate();
}
public void SetVelocity(float v)
{
velo = v;
}
}
Problem #1
PlayableDirector is set to Manual & PlayOnAwake is off & script is enabled
The first weird behavior happens when I leave this script enabled and start up the scene. My timeline anim is about 360 frames (6 sec) and for some reason it will always start around frame 150 (2:45 sec).
No idea why that’s happening, but I managed to avoid that bug by leaving this script disabled at first and then enabling it once the scene is loaded & running.
It even plays the animation on the timeline correctly (moving the object’s transform), but
Problem #2
PlayableDirector is set to Manual & PlayOnAwake is off & script is disabled at first
The objects will move on the trajectory defined in the timeline, but are stuck in a resting pose instead of playing their ‘local’ animation properly, like when Game Time is the updateMode. I’m guessing I somehow need to trigger the evaluation of that animator controller manually as well?
I tried to look into how this works by checking out the Unity source code, and I found this but I’m a bit stuck and don’t know where to look further. Where can I see the code that handles Game Time updating? I figured I could reverse engineer it that way perhaps, but I admit I don’t entirely understand the timeline mechanism yet.
Any ideas/help appreciated, thanks!