So, I have a graph view where I manage and create nodes with Timeline assets and directors assigned to them. It’s here very important to be able to create new ones with just the click of button, and I got it to work just as I want to, with one exception: The Timeline assets that I create and save gets corrupted after a while!
It all seems to be working great for a while, I add some more clips, modify them, save the asset (and the scene), and then suddenly it is corrupted and all of the work that I have done is just gone. The track that I created automatically when creating the timeline asset just disappears, and ofc all the clips with it! I can’t for the life of me understand what I am doing wrong, so is this is a bug? I have read all the sources I can find, and I don’t think I am doing it wrong… Please help!
The code I use to create the asset, the track and the first clip:
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath($"{nextPath}{infoObject.CharacterName} - {nodeName}.playable");
TimelineAsset newTimelineAsset = ScriptableObject.CreateInstance<TimelineAsset>();
TrackAsset track = newTimelineAsset.CreateTrack<DialogTrack>(null, "Dialog track");
DialogClip dialogClip = ScriptableObject.CreateInstance<DialogClip>();
if (interactableDialogObject.characterData != null)
dialogClip.characterData = interactableDialogObject.characterData;
dialogClip.dialogTextEntries = new DialogTextEntry[1];
dialogClip.dialogTextEntries[0].PauseBeforeStart = .4f;
dialogClip.dialogTextEntries[0].TypeInterval = .04f;
TimelineClip clip = track.CreateClip<DialogClip>();
clip.asset = dialogClip;
clip.start = 0;
clip.duration = 5;
AssetDatabase.CreateAsset(newTimelineAsset, assetPathAndName);
director.playableAsset = newTimelineAsset;
DialogObject dialogObject = GameObject.FindObjectOfType<DialogObject>();
if (dialogObject != null)
{
director.SetGenericBinding(track, dialogObject);
}
director.time = 3f;
EditorUtility.SetDirty(dialogClip);
EditorUtility.SetDirty(track);
EditorUtility.SetDirty(newTimelineAsset);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
I am not getting any errors and there is not much to show either, it’s just an empty timeline asset left.