Running TimelineComponent on alternate thread

Hi, I’m trying to optimise our PS4 project and I’m looking for a way to offload blueprint TimelineComponent tasks off the main thread onto another thread. Can this be done ? We’re being absolutely choked by appalling blueprint performance on the main thread.

I can’t find any examples of how to do this on the internet so if there is a way could you show me how to do it too ? Or point me at an example with source code ?



What exactly do you mean by TimlineComponent tasks? Are you talking about events that are fired from the timeline, or the actual calculation of the values in the timeline itself?

In the first case, you should just be able to receive the events and trigger a new task to be evaluated on a new thread. Here is some general documentation about Threading in UE4: Threading

If you’re talking just about the normal behavior, currently it’s run from ticks. This may be a little trickier to set up correctly, and realistically the logic for evaluating the curves is fairly simple so you probably wouldn’t gain much (or anything) if you set them up correctly. The reason I say this is because you’d want to make sure that you copied all mutable state to some sort of “context” type, and then copy it back once the calculations were finished.

However, if this is still something you want to attempt, you’d have to modify FTimeline and FTimelineComponent slightly. If you want an example, we currently do something similar for handling cloth on USkeletalMeshComponents.

Basically, it looks like this:
FSkeletalMeshComponentClothTickFunction is ticked on the Game Thread.
This calls UpdateClothStateAndSimulate, which copies all relevant state information (UpdateClothSimulationContext).
A new Task is created for each ClothingActor, and the TickFunction that is spawning these new tasks is told not to be marked complete until all these new tasks are completed.

There are a few catches with this approach:
First, as mentioned some performance is lost due to copying context information back and forth.
Second, the Tick function is not considered complete until the parallel tasks are finished. What this means is that Timelines may still be a bottle neck if they are the last or only Tick functions executed within their Tick group. Also, since you have extra performance overhead, if there are a relatively small number of Tick functions being called, this still may be a non-optimal approach.

In either case, you should try to do some more testing and profiling to make sure this is your problem.

Alternatively, in 4.12.5 (and potentially earlier iterations of 4.12) there is an experimental feature that can compile Blueprints to C++. This is something you might consider trying if you’re biggest bottleneck is in fact blueprints. However, keep in mind it is experimental and only works in packaged builds.

This setting can be found here:
Project Settings > Project > Packaging > Experimental > Nativize Blueprint Assets.

Jon N.