[Editor] how to set TimelineClip as Selection.activeObject

[Editor] Having the TimelineClip object (obtained through reflection), how can I set it as current selection.activeObject so that Inspector opens it?
thx

TLDR: There isn’t really a public way to do it and maintain the same inspector as Timeline.

TimelineClip doesn’t derive from UnityEngine.Object, so it is not selectable. We work around that by using a scriptableobject that is have it reference the clip.

    class EditorClip : ScriptableObject
    {
        public TimelineClip m_Clip;
    }

We then select the editor clip. You can do the same, but the inspector is tied to our internal editor clip type, so you won’t get the property inspector if you use your own type.

How can I get the EditorClip from TimelineClip object?

You can’t, but if you use the class above, you can create one using ScriptableObject.CreateInstance(). Then set the m_Clip variable, and assign it to Selection.activeObject.

UnityEditor.Timeline.EditorClip is an internal class, thus I cannot access it :frowning:

EDIT: how can I use reflection for this?

Type type = Type.GetType("UnityEditor.Timeline.EditorClip, UnityEditor.Timeline");
object editorclip = ScriptableObject.CreateInstance(type);
FieldInfo mclp = type.GetField("m_Clip");//doesnt exist?
PropertyInfo clp = type.GetProperty("clip");

How can I access the TimelineClip from my clip (that inherits : PlayableAsset, ITimelineClipAsset) ?
Once I get that I could just set the value of clp.

Ok I got the TimelineClip but without selecting the PlayableDirector gameobject from the scene, it’s empy.
Selection.SetActiveObjectWithContext(editorClip, director) doesnt help

The inspector for the clip relies on the timeline window being open. See if just having the window open helps.

Yes, but how can I open the Timeline and Clip with the one (or two) calls?

Try this to open the timeline window, before selecting the editor clip.

Type type = Type.GetType("UnityEditor.Timeline.TimelineWindow, UnityEditor.Timeline");
EditorWindow.GetWindow(type, false, null, false);

I think opening the timeline window is not enough…I should also set the Director that controls the Timeline