Disable Timeline editor window "Preview" from code

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?

Bump

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:

            var enabled = state.previewMode;
            enabled = GUILayout.Toggle(enabled, DirectorStyles.previewContent, EditorStyles.toolbarButton);
            if (EditorGUI.EndChangeCheck())
            {
                // turn off auto play as well, so it doesn't auto reenable
                if (!enabled)
                {
                    state.SetPlaying(false);
                    state.recording = false;
                }

                state.previewMode = enabled;

                // if we are successfully enabled, rebuild the graph so initial states work correctly
                // Note: testing both values because previewMode setter can "fail"
                if (enabled && state.previewMode)
                    state.rebuildGraph = true;
            }

(=> 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)

1 Like