Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Question Set Custom Clip Duration

Discussion in 'Timeline' started by GeniusKoala, Nov 28, 2022.

  1. GeniusKoala


    Oct 13, 2017

    I am coding a custom playable to read data from an external file and I want to be able to read it from a timeline. I read a file to fill an array of string so now I would like the duration of the clip to be the length of this array. So far so good but I wonder how to program the "C" shortcut like for Unity animation clips to automatically set the lenght of the clip with the duration of the content. Like if an animation lasts 2sec, if you select it in the timeline and press the "C" shortcut the clip will have a 2sec duration in the timeline. How to do that for a custom playable please?

    Thanks for helping!
  2. superarhow


    Mar 24, 2015
    Hello, unfortunately the "C" function is not public. So you can call it via reflection:
    Code (CSharp):
    1.     public static void DoMatchContent()
    2.     {
    3.         var method = typeof(TimelineEditor).Assembly.GetType("UnityEditor.Timeline.ClipModifier").GetMethod("MatchContent",
    4.             0, new System.Type[] { typeof(IEnumerable<UnityEngine.Timeline.TimelineClip>) } );
    5.         method.Invoke(null, new object[] { TimelineEditor.selectedClips });
    6.     }
    or, you can send the key directly:
    Code (CSharp):
    1.     public static void DoMatchContent2()
    2.     {
    3.         var e = Event.KeyboardEvent("C");
    4.         EditorWindow.focusedWindow.SendEvent(e);
    5.     }
    ※ You need to call with timeline's editor window opened.
    GeniusKoala likes this.