I’m creating a custom track to make NPCs follow a path of points specified in a custom clip and I’m having an issue because I’ve discovered that when, in play mode, I change between different GameObjects in the hierarchy view and I go back to the timeline, it is recreated.
My question is if it is an expected behavior in Timeline that the track and its clips can be recreated when the Timeline UI is recreated.
I’ve created a simple project with the minimum code needed to create a custom track and a custom clip to help you understand the issue (I’m only adding the gif)
For clarity, the track and clip don’t get recreated (they are assets). The Timeline Editor window, however, may cause the PlayableGraph (runtime representation of the timeline) to be rebuilt, which means your PlayableBehaviours will get destroyed and recreated.
Seant, I’m following this for a similar concept. To be able to mute and unmute tracks. Which means we really have to yank them from the PlayableGraph to have any impact during runtime. How heavyweight is the process of rebuilding the graph? It seems a heinously bad thing to do, but since actual mute doesn’t work during run, it’s really the only way to do it. Thx.
Then how could I initialize a clip’s behaviour? I was doing it when the clip (that inherits from PlayableAsset) was created but since it can be recreated there should be a better way right?
The clip can be initialized in your PlayableAsset.CreatePlayable override, or OnBehaviourPlay, or OnGraphStart. It depends what you mean by initialize. Any data the user can change should be on the Asset, (or a template of PlayableBehaviour), and copied to Behaviour when it is created.
From a design perspective the PlayableBehaviour is an ‘instance’ of the clip - meaning, it can be destroyed/recreated as needed, or there can be multiple copies active at once (for example, two PlayableDirectors playing the same timeline with different bindings - each one will use the same assets, but have different instances).
The editor does try to rebuild minimally, but it does happen.