ts.UseAsyncTargetingTimeSlicing

ts.UseAsyncTargetingTimeSlicing

#Overview

name: ts.UseAsyncTargetingTimeSlicing

This variable is created as a Console Variable (cvar).

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of ts.UseAsyncTargetingTimeSlicing is to control whether the targeting system in Unreal Engine 5 uses time slicing for the asynchronous targeting request queue. This setting is part of the GameplayTargetingSystem, which is an experimental plugin for managing targeting in gameplay scenarios.

This setting variable is primarily used in the GameplayTargetingSystem plugin, specifically within the TargetingSubsystem module. It affects how the targeting system processes asynchronous requests, potentially improving performance by spreading the workload across multiple frames.

The value of this variable is set using an FAutoConsoleVariableRef, which means it can be changed at runtime through console commands. It is initialized to true by default.

The associated variable bUseAsyncTargetingTimeSlicing directly interacts with ts.UseAsyncTargetingTimeSlicing. They share the same value, with bUseAsyncTargetingTimeSlicing being the actual boolean variable used in the code logic.

Developers must be aware that enabling this variable (which is the default behavior) will cause the targeting system to process asynchronous requests in time-sliced chunks. This can help prevent frame rate drops by distributing the workload, but it may also introduce a slight delay in completing all targeting requests.

Best practices when using this variable include:

  1. Keep it enabled (true) for most scenarios to maintain smooth frame rates.
  2. Consider disabling it (false) if immediate targeting results are critical and the performance impact is acceptable.
  3. Use in conjunction with ts.MaxAsyncTickTime to fine-tune the time-slicing behavior.
  4. Monitor performance metrics to ensure the chosen setting provides the best balance between responsiveness and frame rate stability.

Regarding the associated variable bUseAsyncTargetingTimeSlicing:

This is the actual boolean variable used in the TargetingSubsystem’s code logic. It directly controls whether time slicing is applied during the Tick and ProcessTargetingRequestTasks functions. When true, these functions will check the elapsed time after processing each task or request and exit early if the allocated time (defined by ts.MaxAsyncTickTime) has been exceeded. This prevents the targeting system from monopolizing the frame time, allowing other game systems to run smoothly.

Developers should be aware that this variable is used in performance-critical sections of the code. Changes to its value will have an immediate effect on how the targeting system processes requests, potentially affecting both performance and gameplay responsiveness.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Plugins/Experimental/GameplayTargetingSystem/Source/GameplayTargetingSystem/Private/TargetingSystem/TargetingSubsystem.cpp:24

Scope (from outer to inner):

file
namespace    TargetingSystemCVars

Source code excerpt:

	static bool bUseAsyncTargetingTimeSlicing = true;
	FAutoConsoleVariableRef CvarUseAsyncTargetingTimeSlicing(
		TEXT("ts.UseAsyncTargetingTimeSlicing"),
		bUseAsyncTargetingTimeSlicing,
		TEXT("Toggles whether the targeting system will use time slicing for the async targeting request queue. (Enabled: true, Disabled: false)")
	);

	static float MaxAsyncTickTime = .01f;
	FAutoConsoleVariableRef CvarMaxAsyncTickTime(

#Associated Variable and Callsites

This variable is associated with another variable named bUseAsyncTargetingTimeSlicing. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Plugins/Experimental/GameplayTargetingSystem/Source/GameplayTargetingSystem/Private/TargetingSystem/TargetingSubsystem.cpp:22

Scope (from outer to inner):

file
namespace    TargetingSystemCVars

Source code excerpt:

namespace TargetingSystemCVars
{
	static bool bUseAsyncTargetingTimeSlicing = true;
	FAutoConsoleVariableRef CvarUseAsyncTargetingTimeSlicing(
		TEXT("ts.UseAsyncTargetingTimeSlicing"),
		bUseAsyncTargetingTimeSlicing,
		TEXT("Toggles whether the targeting system will use time slicing for the async targeting request queue. (Enabled: true, Disabled: false)")
	);

	static float MaxAsyncTickTime = .01f;
	FAutoConsoleVariableRef CvarMaxAsyncTickTime(
		TEXT("ts.MaxAsyncTickTime"),

#Loc: <Workspace>/Engine/Plugins/Experimental/GameplayTargetingSystem/Source/GameplayTargetingSystem/Private/TargetingSystem/TargetingSubsystem.cpp:207

Scope (from outer to inner):

file
function     void UTargetingSubsystem::Tick

Source code excerpt:

			ProcessTargetingRequestTasks(TargetingHandle, TimeLeft);

			if (TargetingSystemCVars::bUseAsyncTargetingTimeSlicing)
			{
				const double StepDuration = (FPlatformTime::Seconds() - StepStartTime);
				TARGETING_LOG(VeryVerbose, TEXT("UTargetingSubsystem::Tick - Finished Processing Async Request [%d] in [%f] seconds."), RequestIterator, StepDuration);

				TimeLeft -= StepDuration;
				if (TimeLeft <= 0.0f)

#Loc: <Workspace>/Engine/Plugins/Experimental/GameplayTargetingSystem/Source/GameplayTargetingSystem/Private/TargetingSystem/TargetingSubsystem.cpp:625

Scope (from outer to inner):

file
function     void UTargetingSubsystem::ProcessTargetingRequestTasks

Source code excerpt:


							// if we are out of time, save the task for the next time
							if (TargetingSystemCVars::bUseAsyncTargetingTimeSlicing)
							{
								const double StepDuration = (FPlatformTime::Seconds() - StepStartTime);
								TARGETING_LOG(VeryVerbose, TEXT("UTargetingSubsystem::ProcessTargetingRequestTasks - Finished Processing Task [%s] in [%f] seconds."), *(GetNameSafe(Task)), StepDuration);

								TimeLeft -= StepDuration;
								if (TimeLeft <= 0.0f)