How to change the length of a Timeline in Unreal Engine

- by

Timelines are behind a lot of the animation magic in Unreal Engine Blueprints. I’ve been implementing one to make my plants grow on Jay’s Farm, but I needed a functionality that would let me change the duration of my parent timeline with a variable. That way different seeds could grow with different rates.

There’s no obvious way to plugin a “duration” value, but we can change the Playback Rate once a Timeline is established. Here’s how I’ve made it work.

First there’s the regular timeline setup. I’ve used a custom event here because Timeline Nodes cannot be used in functions. The duration of my timeline is 1 second so I can override it easily in the next step.

For my project, the above event is called right after Begin Play. Right after I call it, I can grab a reference to it and call Set Play Rate on the Timeline. This will now slow it down or speed it up, according to the New Rate value we can pass in there.

By making the original timeline 1 second in duration, I can pass in a value of 0.1 to make it play 10x longer (i.e. 10 seconds), or 0.01 to make it 100x longer (i.e. 100 seconds). To make this calculation a little easier, I’m dividing 1 by the value I’ll pass in (Growth Rate). That way I can pass in 20 and it’ll play for 20 seconds.

And another Unreal Engine mystery has been solved!

If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site witout any pesky ads! More details here.

Add your voice