Actor Ticking
- "Ticking" refers to running code or Blueprint script on an actor or component at regular intervals, usually once per frame. Understanding order is essential to avoid off-by-one frame issues. Actors and components can tick each frame, at set minimum intervals, or not at all; grouped into phases; can wait for specific ticks.
- Each tick group will finish ticking every actor and component assigned to it before the next tick group begins. Tick dependency: will not tick until the specified other tick function is finished.
- Order: TG_PrePhysics (beginning of frame) -> TG_DuringPhysics (physics simulation has begun) -> TG_PostPhysics (physics complete) -> [latent actions, world timer manager, cameras, level streaming] -> TG_PostUpdateWork -> [deferred spawning; finish frame and render].
- TG_PrePhysics: for actors interacting with physics incl. physics-based attachments; physics data here is one frame old.
- TG_DuringPhysics: unknown whether physics data is previous or current frame; for logic not caring about physics (inventory screens, minimap).
- TG_PostPhysics: this frame's physics complete; weapon or movement traces, laser sights.
- TG_PostUpdateWork: after cameras updated; last-moment info into particle systems; e.g. resolving two characters grabbing each other on the same frame in a fighting game.
AddTickPrerequisiteActor/AddTickPrerequisiteComponent. Reason to use over tick group: many actors can be updated in parallel if in the same group; moving to a new group might not be needed if only individually dependent on one or two others.- Example: animated aiming actor in PrePhysics; HUD in DuringPhysics (one frame behind); reticule in PostPhysics; laser particle in PostUpdateWork or in PostPhysics with dependency on reticule (more efficient). Reticule needs no dependency on aiming actor because different groups already guarantee order.
- In
BeginPlay, an actor registers its primary tick function and its components' tick functions.PrimaryActorTick.bCanEverTick,.bTickEvenWhenPaused,.TickGroupusually set in constructor. Components:PrimaryComponentTick,TickComponent(). SetActorTickEnabled/SetComponentTickEnabled. Multiple tick functions via struct inheritingFTickFunctionoverridingExecuteTickandDiagnosticMessage; register via overridingAActor::RegisterActorTickFunctions,SetTickFunctionEnable,RegisterTickFunction;AddPrerequisite.