Hi everyone, I'm currently working on a script, a part of which allows the user to select an AnimatorClip (as a TimelineClip in an AnimationTrack) he wants to record again, and then creates a "ghost" of that object with a copy of its AnimatorTrack. Second track is the one that is copied, fourth one its "ghost" copy At the end of the recording process, the "ghost" AnimatorTrack has to be deleted. While destroying the "ghost" GameObject functions properly, I get this result by using the TimelineAsset.DeleteTrack method : The thing to notice is the "remaining of the track" on the Timeline. As long as it's here, i get these three errors that gets repeated each time I try to interact with the Timeline : First two don't point to any part of the script when double-clicking them, and third one points to the Unity Editor window itself through the Inspector. A simple Ctrl+Z removes this "remaining" : And another Ctrl+Z is needed to make the track that has been deleted appear again, even though "Edit - Undo" directly makes that track appear again. This all seems to be a problem of refreshing the Timeline after the track has been deleted. Any advice to give ?
Hello Sean, Thank you for your answer. I initially didn't use that Refresh function as it was a TimelineEditor method, which can only be used in an Editor script ; I ended up solving that problem by using delegates, and using the method you mentionned. If anyone encounters the same problem, it might not be the best solution, but here is my workaround. In your MonoBehaviour script, I added the following : Code (CSharp): public delegate void DestroyGhostDelegate(); public static DestroyGhostDelegate OnDestroyGhost; [...] private void OnDisable() { timeline.DeleteTrack(ghostTrack); //timeline is a Timeline Asset, ghostTrack is an AnimationTrack if (OnDestroyGhost != null){OnDestroyGhost();} } In my "Scripts" folder, I added an "Editor" folder, which is required to create Editor script. I added this script in the folder : Code (CSharp): using UnityEditor; using UnityEditor.Timeline; public class DestroyGhostEditor : Editor { [InitializeOnLoadMethod] static void Init() { InputRecorderTimeline.OnDestroyGhost = RefreshTracks; } public static void RefreshTracks() { TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved); } } In the end the track gets removed properly with this. Hope it will help someone else !
So this happens only when trying to delete tracks on a Timeline asset on disk during runtime. Correct? I tried runtime Timeline asset instances and they didn't have any issues so I no longer need the Timeline asset on disk(all of my content is procedurally generated or loaded on runtime from non compiled assets) and I had no other tracks added before so I had no reason to stick with a disk asset. Though I now wonder whether I could use a disk asset as a template and instantiate the same thing on memory and extend it but destroy it completely at the end.