I’m trying to add a TimelineAsset to a ControllTrack with C# and it is working. However when I restart Unity or reload the scene the connection is lost. If I however add the same GameObject (with the PlayableDirector) manually via the Inspector then Unity will remember it. I’ve tried using
AssetDatabase.SaveAssets()
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene(), EditorSceneManager.GetActiveScene().path)
EditorApplication.ExecuteMenuItem(“File/Save Project”)
EditorUtility.SetDirty()
to try to force Unity to save the changes in the assets but it does not help. Saving manually from the Editor UI does not help either.
This is the code I use to set the GameObject with the PlayableDirector for the second timeline (called sequence) to be played from a ControlTrack in the first timeline (called profile). As I said this code works, the Source Game Object field in the Control Playable Asset looks like it is set properly in the Inspector and the animation (sequence) plays as expected but when I save the scene and reloads it, this connection is gone (Source Game Object field set to None), but if I set it manually (drag-n-drop the GameObject with the PlayableDirector for the second timeline to the field Source Game Object in the ControlTrack via the Inspector) and save the scene it works fine to reload the scene, nothing is lost, everything keeps working.
var profile = parentProfile.GetComponent<PlayableDirector>().playableAsset as TimelineAsset;
ControlTrack sequenceTrack = profile.CreateTrack<ControlTrack>(null, sequence.name);
var sequenceClip = sequenceTrack.CreateClip<ControlPlayableAsset>();
sequenceClip.displayName = sequence.name;
var controlAsset = (ControlPlayableAsset)sequenceClip.asset;
controlAsset.sourceGameObject.defaultValue = sequenceDirector.gameObject;
I’m using Unity 2019.1.14 and have tried it in 2019.2.9 but I get the same result in both versions. @seant_unity do you have an explanation and/or workaround for this?