Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Disable Timeline editor window "Preview" from code

Discussion in 'Timeline' started by AverageProg, Sep 14, 2022.

  1. AverageProg

    AverageProg

    Joined:
    Jun 25, 2015
    Posts:
    38
    I am building a custom animation timeline and I am giving the opportunity to set the begin and end values
    of the animation directly from a ClipAction, the problem is that the preview is always on and I need to take the driven component value without it being affected by the preview.
    been looking around for a while now, is there any solution to this?
     
  2. cspid

    cspid

    Joined:
    Apr 25, 2014
    Posts:
    34
    Bump
     
  3. Yuchen_Chang

    Yuchen_Chang

    Joined:
    Apr 24, 2020
    Posts:
    140
    I've checked the APIs, but seems that there is no public API for this. If you really want, there are internal features/classes that can do this.
    According to TimelineWindow_HeaderGui.cs, preview button is actually doing this:
    Code (CSharp):
    1.             var enabled = state.previewMode;
    2.             enabled = GUILayout.Toggle(enabled, DirectorStyles.previewContent, EditorStyles.toolbarButton);
    3.             if (EditorGUI.EndChangeCheck())
    4.             {
    5.                 // turn off auto play as well, so it doesn't auto reenable
    6.                 if (!enabled)
    7.                 {
    8.                     state.SetPlaying(false);
    9.                     state.recording = false;
    10.                 }
    11.  
    12.                 state.previewMode = enabled;
    13.  
    14.                 // if we are successfully enabled, rebuild the graph so initial states work correctly
    15.                 // Note: testing both values because previewMode setter can "fail"
    16.                 if (enabled && state.previewMode)
    17.                     state.rebuildGraph = true;
    18.             }
    (=> when turned off, stop playing; when turned on, rebuild the graph)
    the "state" refers to WindowState, which you can retrieve it by
    TimelineEditor.state
    . However, it is an internal property, so you may need reflection, or use asmref to expose new public APIs to stop/start preview. (asmref allows you to add new script to packages)
     
    fxlange likes this.