How to determine the order of C++ classes executed in the game loop?

Suppose in Unreal you have two C++ classes, and both of them are using the Tick(DeltaTime) function. How do you determine which of those Tick functions is going to be called first in the game loop?

Simple question really. Hope someone can help!

There is some info about Actor Ticking here:

If you want one actor to tick before another you can setup a tick dependency.

Otherwise if both actors are in the same tick group, I think it’s unspecified what order they will tick in.

Hello! Engine is calling Tick method, within that method current World is calling own Tick method, within that method Level collection of Actors is iterated and each Actor is calling own Tick method. As mentioned by @zos it is rather risky to build logic around “natural” Tick calls order…

Thanks that helps. It would be good to see some code examples of setting up a “tick dependency”.

The best way to find code examples is to do a code search for the function or class in question in the UE5 engine which you can do from your IDE.

For example in the Tick Dependency section of the Actor Ticking page I sent you they describe the AddTickPrerequisiteActor function, which if you do a code search in your IDE you will find examples like:

void AGameplayAbilityWorldReticle::InitializeReticle(AActor* InTargetingActor, 
APlayerController* PlayerController, FWorldReticleParameters InParameters)
{
	check(InTargetingActor);
	TargetingActor = InTargetingActor;
	MasterPC = PlayerController;
	AddTickPrerequisiteActor(TargetingActor);		//We want the reticle to tick after the targeting actor so that designers have the final say on the position
	Parameters = InParameters;
	OnParametersInitialized();
}
1 Like

I’m wondering though… I have a C++ class, and a blueprint that inherits from that class. How would I get the blueprint code to tick before the C++ ticks?

That’s a good question, I’m not sure but if both the blueprint subclass and its C++ base class are ticking then the Blueprint Tick must call Super::Tick, I’m not sure if you can change the order of that. To investigate you can set a breakpoint on the C++ base classes Tick function and then run it in the debugger and see who is calling it.