Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

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

Discussion in 'Timeline' started by mhofer, Nov 9, 2017.

  1. mhofer

    mhofer

    Joined:
    Aug 30, 2017
    Posts:
    18
    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!
     
  2. jonathangutman

    jonathangutman

    Joined:
    Dec 6, 2016
    Posts:
    5
    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();​
     
    ModLunar likes this.
  3. mhofer

    mhofer

    Joined:
    Aug 30, 2017
    Posts:
    18
    Great, thanks! Getting the window and calling timelineWindow.Focus() did the trick!
     
  4. foehnlol

    foehnlol

    Joined:
    Nov 30, 2016
    Posts:
    2
    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.
     
  5. mhofer

    mhofer

    Joined:
    Aug 30, 2017
    Posts:
    18
    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?
     
  6. foehnlol

    foehnlol

    Joined:
    Nov 30, 2016
    Posts:
    2
    Still not working...
    I guess I have to wait for an offical way to refresh the timeline editor window.
    Thank you anyway!
     
  7. zzd

    zzd

    Joined:
    Jul 6, 2012
    Posts:
    3
    Another method,close ,and show agin!!!
     
  8. IvanIvanovP3

    IvanIvanovP3

    Joined:
    Jan 24, 2021
    Posts:
    2
    Type timelineWindowType = Type.GetType("UnityEditor.Timeline.TimelineWindow,UnityEditor.Timeline");
    not working for me, may be because now class TimelineWindow is internal, not public?
     
unityunity