TickGroup defaults for CameraComponent and SceneComponent

I’ve noticed that the default tick group for the tick functions on (at least) the CameraActor, CameraComponent, and SceneComponent are set to TG_DuringPhysics. I was wondering if there was a specific reason for that default. Some of our use cases have those objects attached to objects which are ticking in TG_PrePhysics, so we’re seeing tick group demotion happen as a result, which is something we’d like to avoid. I’ve experimented with changing those values and didn’t see any issues, but I wanted to see if there was a deeper reason that wasn’t apparent to me.

Thanks!

- Alex

Steps to Reproduce

Since the physics calculations for a game frame can’t start until all TG_PrePhysics components have ticked, the main reason to put components in TG_DuringPhysics is so they don’t needlessly delay the starting of physics work in a frame.

The default for ActorComponent being TG_DuringPhysics is because most components don’t need to do work that’s a dependency for physics work. If you change a component’s tick group from currently TG_DuringPhysics to TG_PrePhysics, the main drawback will be that it will delay physics calculations for the frame by the time it takes to tick those components. Whether that’s noticeable or not in your project would require profiling. Does that answer your question?

To build on top of Zhi’s answer, in most games PrePhysics is the performance bottleneck so we want things to happen later if possible. In most games camera movement does not affect physics so it is usually a good thing to run in parallel with physics.

Actor/Scene Components do not tick at all by default, so if you add ticking to a subclass you should set the tick group to whatever is appropriate for your game. By default AttachToComponent sets up a tick dependency so the child attaches to the parent, but you can remove that by calling RemoveTickPrerequisiteComponent if you do not want it. This dependency will only apply if the parent actually ticks, so if you attach a ticking thing to a SceneComponent that does not tick by default it will ignore the dependency. The automatic tick dependency setup does not always work well and many games override it manually.

I do not recommend changing the default in ActorComponent.cpp as that would modify many components you do not want to change.

Thanks for your responses Zhi and Ben!

Just to double check my understanding, physics tick will wait for everything started during TG_PrePhysics to complete, regardless of the EndTickGroup of those tick functions? For instance, if I have a particularly expensive tick function that does not run on the Game Thread, but has its TickGroup set to PrePhysics and its EndTickGroup set to EndPhysics, that will delay the start of physics processing?

Indeed your understanding of EndTickGroup is correct, my first response was a bit sloppy in that regard!

Checking in here if all your questions are now answered with regards to those components their default tick group, and tick groups in general.

The EndTickGroup is what matters for deciding when it can start the next group. If you have a TickGroup of PrePhysics and an EndTickGroup of EndPhysics, it will not wait for that task to complete before going to StartPhysics. In your case that should not delay physics processing.

We’re making several fixes to async/worker thread ticking in UE 5.6 so I’m not 100% sure it will work properly in 5.5 as the bRunOnAnyThread code path was not well tested. If it doesn’t, you can take a look at some of the changes to TickTaskManager.cpp in the Main branch of github (I’ve made a lot of changes recently)

Ok good. That tracks with my understanding of how EndTickGroup functions, and also is supported by what we’ve seen in our profiling captures.

Just to make expectations clear, are you saying that the bRunOnAnyThread path was/is not well tested in 5.5, or in the changes that are coming in 5.6?

I’ll definitely check out those changes. Thanks for pointing that out!

bRunOnAnyThread had some issues in 5.5, but is working a lot better in 5.6/current Main branch. When 5.6 is released we’ll have some notes on how to use the new tick features