Search Unity

[Editor] how to set TimelineClip as Selection.activeObject

Discussion in 'Timeline' started by Flag74, Oct 5, 2018.

  1. Flag74

    Flag74

    Joined:
    May 31, 2017
    Posts:
    128
    [Editor] Having the TimelineClip object (obtained through reflection), how can I set it as current selection.activeObject so that Inspector opens it?
    thx
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    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.

    Code (CSharp):
    1.     class EditorClip : ScriptableObject
    2.     {
    3.         public TimelineClip m_Clip;
    4.     }
    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.
     
  3. Flag74

    Flag74

    Joined:
    May 31, 2017
    Posts:
    128
    How can I get the EditorClip from TimelineClip object?
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    You can't, but if you use the class above, you can create one using ScriptableObject.CreateInstance<EditorClip>(). Then set the m_Clip variable, and assign it to Selection.activeObject.
     
  5. Flag74

    Flag74

    Joined:
    May 31, 2017
    Posts:
    128
    UnityEditor.Timeline.EditorClip is an internal class, thus I cannot access it :(

    EDIT: how can I use reflection for this?
     
  6. Flag74

    Flag74

    Joined:
    May 31, 2017
    Posts:
    128
    Code (CSharp):
    1. Type type = Type.GetType("UnityEditor.Timeline.EditorClip, UnityEditor.Timeline");
    2. object editorclip = ScriptableObject.CreateInstance(type);
    3. FieldInfo mclp = type.GetField("m_Clip");//doesnt exist?
    4. 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.
     
    Last edited: Oct 19, 2018
  7. Flag74

    Flag74

    Joined:
    May 31, 2017
    Posts:
    128
    Ok I got the TimelineClip but without selecting the PlayableDirector gameobject from the scene, it's empy.
    Selection.SetActiveObjectWithContext(editorClip, director) doesnt help
     
  8. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    The inspector for the clip relies on the timeline window being open. See if just having the window open helps.
     
  9. Flag74

    Flag74

    Joined:
    May 31, 2017
    Posts:
    128
    Yes, but how can I open the Timeline and Clip with the one (or two) calls?
     
  10. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Try this to open the timeline window, before selecting the editor clip.

    Code (CSharp):
    1. Type type = Type.GetType("UnityEditor.Timeline.TimelineWindow, UnityEditor.Timeline");
    2. EditorWindow.GetWindow(type, false, null, false);
    3.  
     
  11. Flag74

    Flag74

    Joined:
    May 31, 2017
    Posts:
    128
    I think opening the timeline window is not enough...I should also set the Director that controls the Timeline
     
    Last edited: Oct 22, 2018