- Home /
Force a timeline clip to a fixed duration
Hi, I am making a new clip for the timeline and it makes no real sense for it to be 'resizable', so I would like to give it a fixed length based on an asset given as a parameter.
I've tried setting the clip duration in the CreateMixer function of the track, but the user can change this by dragging the clip's right side border.
How would i go about doing this?
Thanks!
Answer by seant_unity · Mar 13, 2018 at 11:19 AM
Unfortunately there is no mechanism in place to prevent the user from being able to resize the clip.
Answer by Thomas-Bousquet · Mar 13, 2018 at 01:50 PM
I understand. I think it would be a cool feature to support in the future :)
As 2nd best option, I would like to emulate the AudioClip behavior which set it's proper length when being created; with the resize control 'sticking' a bit at the 'native' duration of the clip. I couldn't find any documentation about this, do you have any pointers?
In your clip's playable asset, you can override the duration property from PlayableAsset. This will set the clip length when using the 'ResetEditing' function. If the sub asset isn't assigned yet, then it won't set the initial length correctly, but should give you the same sticking behaviour as AudioClip.
This is something that specifically looking at to improve in 2018.2, to better support custom track drag and drop, and initial clip length.
Thanks, it works really neatly :) I'm linking to a past answer from the forum which details this solution. https://forum.unity.com/threads/set-playable-duration-in-code.483085/#post-3144555 For anyone who's not sure, this goes in the class that inherits from PlayableAsset. (Thanks to PeryB for the correction)
It's actually in the one that inherits from PlayableAsset
Your answer
Follow this Question
Related Questions
How to reference a TrackAsset or PlayableAsset 2 Answers
How to get the Track and the Clip of a Timeline? 1 Answer
How to get a track from a timeline from a playable director? 1 Answer
Peculiar Bleed-through of Exposed References on different Timeline Tracks 2 Answers
Clip offset do not work in the Timeline, What am I doing wrong? 0 Answers