How to create a TimelineAsset from script and make the Timeline EditorWindow refresh?

I have a script that works with a timeline and when you add it to a GameObject I want it to set up everything automatically. (I automatically add the PlayableDirector, Animator and once I have the TimelineAsset I can automatically add my custom track and add custom clips, BUT I have two issues:

1) What’s the appropriate way to create a TimelineAsset and assign it to the PlayableDirector from an EditorScript?

2) Once I have added the custom track and clips it doesn’t show up in the Timeline EditorWindow until I click on another gameObject and then back on mine. Who can I make the Timeline EditorWindow refresh?

Thank you very much for your help!

For the editorwindow you should be able to do this:
Type timelineWindowType = Type.GetType(“UnityEditor.Timeline.TimelineWindow,UnityEditor.Timeline”);
var timelineWindow = EditorWindow.GetWindow(timelineWindowType);
timelineWindow.Repaint();

1 Like

Great, thanks! Getting the window and calling timelineWindow.Focus() did the trick!

I have the same refreshing problem. I try this but the editorwindow doesn’t seem to be refreshing… then I added timelineWindow.Focus() and still the same. I wonder where did it go wrong, or is there an alternative way to refresh. Thank you.

I also do an Undo.RecordObject(); on the gameObject the director is on (before all of the above). I guess this gives the director a reason to refresh?

Still not working…
I guess I have to wait for an offical way to refresh the timeline editor window.
Thank you anyway!

Another method,close ,and show agin!!!

Type timelineWindowType = Type.GetType(“UnityEditor.Timeline.TimelineWindow,UnityEditor.Timeline”);
not working for me, may be because now class TimelineWindow is internal, not public?