tick.AllowAsyncTickDispatch
tick.AllowAsyncTickDispatch
#Overview
name: tick.AllowAsyncTickDispatch
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
If true, ticks are dispatched in a task thread.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of tick.AllowAsyncTickDispatch is to control whether ticks are dispatched in a task thread or not. This setting is part of Unreal Engine’s tick system, which is responsible for updating game logic and components at regular intervals.
This setting variable is primarily used in the Engine module, specifically within the tick task management system. Based on the callsites, it’s clear that this variable is referenced in the TickTaskManager.cpp file, which is part of the Engine’s runtime.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 0, meaning async tick dispatch is disabled by default. Developers can change this value at runtime using console commands or through configuration files.
The associated variable CVarAllowAsyncTickDispatch interacts directly with tick.AllowAsyncTickDispatch. They share the same value and purpose.
Developers must be aware that enabling this variable (setting it to 1) will cause ticks to be dispatched in a separate task thread. This can potentially improve performance by allowing the game thread to process ticks while other ticks are being queued by another thread. However, it may also introduce threading complexities and potential race conditions if not handled properly.
Best practices when using this variable include:
- Thoroughly testing the game with both enabled and disabled states to ensure stability.
- Profiling the game’s performance to determine if async tick dispatch provides a meaningful benefit.
- Ensuring that all game systems are thread-safe if enabling this feature.
- Using this in conjunction with other tick-related settings for optimal performance.
Regarding the associated variable CVarAllowAsyncTickDispatch:
The purpose of CVarAllowAsyncTickDispatch is to provide programmatic access to the tick.AllowAsyncTickDispatch setting within the C++ code. It’s an instance of TAutoConsoleVariable, which is Unreal Engine’s way of exposing console variables to C++ code.
This variable is used directly in the Engine module, specifically in the TickTaskManager. It’s checked in the ReleaseTickGroup function to determine whether to dispatch tick groups on the game thread or asynchronously.
The value of CVarAllowAsyncTickDispatch is set automatically based on the tick.AllowAsyncTickDispatch console variable. Developers can read its value using the GetValueOnGameThread() method.
CVarAllowAsyncTickDispatch interacts directly with the tick.AllowAsyncTickDispatch console variable, reflecting its value in C++ code.
Developers should be aware that reading this variable’s value should be done using the GetValueOnGameThread() method to ensure thread-safety.
Best practices for using CVarAllowAsyncTickDispatch include:
- Always reading its value on the game thread using GetValueOnGameThread().
- Considering caching the value if it’s accessed frequently, as reading console variables can have a small performance cost.
- Using it in conjunction with other tick-related settings and variables for comprehensive tick system control.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/TickTaskManager.cpp:55
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarAllowAsyncTickDispatch(
TEXT("tick.AllowAsyncTickDispatch"),
0,
TEXT("If true, ticks are dispatched in a task thread."));
static TAutoConsoleVariable<int32> CVarAllowAsyncTickCleanup(
TEXT("tick.AllowAsyncTickCleanup"),
0,
#Associated Variable and Callsites
This variable is associated with another variable named CVarAllowAsyncTickDispatch
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/TickTaskManager.cpp:54
Scope: file
Source code excerpt:
TEXT("If true, queue ticks concurrently."));
static TAutoConsoleVariable<int32> CVarAllowAsyncTickDispatch(
TEXT("tick.AllowAsyncTickDispatch"),
0,
TEXT("If true, ticks are dispatched in a task thread."));
static TAutoConsoleVariable<int32> CVarAllowAsyncTickCleanup(
TEXT("tick.AllowAsyncTickCleanup"),
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/TickTaskManager.cpp:531
Scope (from outer to inner):
file
class class FTickTaskSequencer
function void ReleaseTickGroup
Source code excerpt:
{
SCOPE_CYCLE_COUNTER(STAT_ReleaseTickGroup);
if (SingleThreadedMode() || CVarAllowAsyncTickDispatch.GetValueOnGameThread() == 0)
{
DispatchTickGroup(ENamedThreads::GameThread, WorldTickGroup);
}
else
{
// dispatch the tick group on another thread, that way, the game thread can be processing ticks while ticks are being queued by another thread