Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

How do i set the clipCaps of and Timelineclip?

Discussion in 'Timeline' started by LarsWegmeister, Feb 28, 2018.

  1. LarsWegmeister

    LarsWegmeister

    Joined:
    Feb 9, 2018
    Posts:
    4

    var clip = track.CreateDefaultClip();
    clip.asset = defaultClip.asset;
    double startTime = GetStartTime(defaultClip.start);
    clip.start = startTime;
    clip.duration = defaultClip.duration;
    clip.displayName = defaultClip.displayName;
    clip.clipCaps = defaultClip.clipCaps;


    I want to use this to create a generic Timelineclip.
    The Documentation tells me its public "public Timeline.ClipCaps clipCaps;" but when i try to set "clip.clipCaps = defaultClip.clipCaps;" VS tells me that its protected.

    So how can i set the clipCaps?
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,031
    Clip caps isn't something you set in a script. On a custom clip (i.e. playable asset), if you implement the
    ITimelineClipAsset interface, you let the editor know what type of capabilities your clip has (blending, extraplolation, clip in, etc...) so that the editor properly supports them.
     
  3. LarsWegmeister

    LarsWegmeister

    Joined:
    Feb 9, 2018
    Posts:
    4
    Hmmm than how exactly can i create a Copie of a Clip?
    In my Project i have a narrator who tells a story but we want him to be able to switch the language. So i created a script to use the narrator's audiotrack as the main anchor for every timelineclip. That way we only need to create one Timeline. My script takes that timeline and copies it for the other languages with nearly the right start times of every other clip.
    The only step left to make it work is to change the "Post-Extrapolate" to "hold". Prefarable via script. The creation is manual and not at Runtime.
     
  4. LarsWegmeister

    LarsWegmeister

    Joined:
    Feb 9, 2018
    Posts:
    4
    The only thing i need to do is set the red marked to Hold SetThis..PNG
     
  5. MakinStuffLookGood

    MakinStuffLookGood

    Joined:
    Nov 20, 2012
    Posts:
    14
    I agree that these properties being restricted to a get feels a bit arbitrary. TimelineClip does not inherit from UnityEngine.Object, so you can't just set the values of it like a regular SerializedObject. It does however, implement ISerializationCallbackReceiver. The Timeline API is mysteriously missing from the Unity CSharpReference, but let's just assume that if we set the private fields to the value we want, the clip will serialize itself properly. Because they are private fields— it's Reflection to the rescue:

    Code (CSharp):
    1.             var preExtrpFieldInfo = typeof(TimelineClip).GetField("m_PreExtrapolationMode", BindingFlags.NonPublic | BindingFlags.Instance);
    2.             var postExtrpFieldInfo = typeof(TimelineClip).GetField("m_PostExtrapolationMode", BindingFlags.NonPublic | BindingFlags.Instance);
    3.             preExtrpFieldInfo.SetValue(clip, TimelineClip.ClipExtrapolation.Hold);
    4.             postExtrpFieldInfo.SetValue(clip, TimelineClip.ClipExtrapolation.Hold);
    We just find the two private fields we want and set their values using the ClipExtrapolation enum in TimelineClip.cs. Make sure to call AssetDatabase.SaveAssets() afterwards. This is tested and working in 2017.4.3f1
     
    LarsWegmeister likes this.