Hi, I’m making the basic movement mechanics for a first-person game with sprinting, crouching etc. and currently using timelines for smoothing out the transitions, but I’ve read mixed things about their performance impact. My question is would it be okay using Timelines for things like going from standing<->crouched and walking<->running on the player character since they’re only triggered every so often and only in a single instance, that of the player character, rather than running all the time in the background on countless instances, or should I be looking at Interp/Lerp, timers and loops for these things if I want to reserve the maximum amount of performance and better frametimes for other things. And is it bad to have separate timelines for all of these transitions rather than re-using a single one with a 0 ↔ 1 output plugged into the alpha of an Interp, or does it not matter since Timelines don’t seem to be very re-usable and you get a new one when you copy or duplicate one anyway?
Reason I’m asking is Timelines work so well for these things and I’m not getting good results with Interp so far, but I know the latter is the “preferred” method for things like this, I just don’t know how to get it working properly when it’s not an Event Tick-based thing but rather something triggered by InputActions.
Also, when you have to use Timelines, is it more expensive to use different Timelines for individual actions/events or more expensive to use a single Timeline with several tracks in it firing off different outputs, provided them firing doesn’t interfere with one another?
Performance isn’t everything. If you know how to make it work with Timelines then stick to them instead of introducing bugs. It is a good practice to learn how to Lerp without them though and if the Timeline simply goes from 0-1 then it is not hard to make it with a simple Timer instead.
Internally a Timeline is simply a fancy Component living its own life, so each Timeline node is a new Component. You can even change the curves etc. if you search for the name of your Timeline.
One Timeline will always be better than multiple Timelines but again remember to weight Performance with Maintainability, if it is easy to implement make it with 1 Timeline, if not then use more.
Thanks! I’ll stick with Timelines for now and mess around with Lerps to get the hang of them, my main problem replacing TL with Lerp was getting it to smoothly keep updating until the target value was met given that the trigger is a singular InputAction and not an EventTick but I’ll keep trying, it’s a bit early in my project for performance profiling anyway, and it shouldn’t be a problem replacing it later on should it turn out prohibitively expensive. The curves are actually the main reason I wanted to use TL in the first place, I can always feel in games when movement transitions are linear vs. eased with the latter always feeling somewhat more weighty.
In the Content browser you can create a Curve Asset (Miscellaneous->Curve) and sample this with GetFloatValue (if it is a Float Curve). You can then make a Variable for that curve and easily swap the curve with another from your Content Browser.
The way I make my lerp is either by temporarily enabling and disabling Tick with SetActorTickEnabled and making a time-stamp with GetTimeSeconds on play and calculating each tick if GetTimeSeconds > (TimeStamp + Duration). If I need to know how much time has passed it is GetTimeSeconds - TimeStamp.
I use Timers if the event doesn’t need to trigger every tick (very few things actually needs to tick). The TimerHandle can conveniently be used to get the elapsed time then you don’t need to save a TimeStamp.
If the lerp is not based on time but perhaps DistanceTravelled then promote the DistanceTravelled to a variable and add distance by Speed x GetFloatValue x DeltaTime (Delta being time since last update of DistanceTravelled).