There’s no direct way to change the duration value of a timeline at runtime, however since there is a way to change the playback rate of a timeline, you can use this simple workaround:
-
Make your timeline 1 second in duration.
-
Create a float variable that will act as the new, dynamic duration of your timeline.
-
Get a reference to your timeline (Get )
-
Set Playback Rate on your timeline to 1 divided by your new float variable.
Since your timeline is 1 second long, dividing 1 by the desired duration will result in your timeline playing for exactly that desired duration (1 / 4 = 0.25, 1 second timeline playing at 0.25 speed = 4 seconds).
Timelines tick once per frame, regardless of their playback rate, so this effectively changes the timeline’s duration.