SpewAnimRateOptimization

SpewAnimRateOptimization

#Overview

name: SpewAnimRateOptimization

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 SpewAnimRateOptimization is to enable logging of animation rate optimization tick rates in Unreal Engine’s skeletal mesh animation system.

This setting variable is used in the Engine module, specifically within the SkeletalMeshComponent class. It’s part of the animation system and is used for debugging and performance analysis purposes.

The value of this variable is set through a console variable (CVar) named CVarSpewAnimRateOptimization. It’s initialized with a default value of 0, which means the logging is disabled by default.

The associated variable CVarSpewAnimRateOptimization is a TAutoConsoleVariable that directly controls the behavior. When its value is greater than 0, it enables the logging of animation tick rates.

This variable interacts with two FThreadSafeCounter variables named Ticked and NotTicked, which keep track of the number of times the skeletal mesh component has been ticked or not ticked, respectively.

Developers should be aware that enabling this logging (by setting the console variable to a value greater than 0) may have a performance impact, especially in production builds. It’s primarily intended for debugging and optimization purposes.

Best practices for using this variable include:

  1. Only enable it when actively debugging animation performance issues.
  2. Be cautious about enabling it in production builds, as it may affect performance.
  3. Use it in conjunction with other profiling tools to get a comprehensive view of animation system performance.
  4. Remember to disable it after debugging to avoid unnecessary overhead.

Regarding the associated variable CVarSpewAnimRateOptimization:

This is the actual console variable that controls the behavior. It’s an integer variable, where values greater than 0 enable the logging. It’s accessed using GetValueOnGameThread() method, which suggests it’s designed to be thread-safe and primarily used on the game thread.

The variable is checked in the TickPose function of USkeletalMeshComponent. When enabled, it logs the number of ticked and not ticked instances every 500 ticks, providing insights into the animation update frequency.

Developers can modify this value at runtime using console commands, making it a flexible tool for on-the-fly debugging. However, they should be cautious about leaving it enabled in production code due to the potential performance overhead of frequent logging.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/SkeletalMeshComponent.cpp:1581

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarSpewAnimRateOptimization(
	TEXT("SpewAnimRateOptimization"),
	0,
	TEXT("True to spew overall anim rate optimization tick rates."));

void USkeletalMeshComponent::TickPose(float DeltaTime, bool bNeedsValidRootMotion)
{
	Super::TickPose(DeltaTime, bNeedsValidRootMotion);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/SkeletalMeshComponent.cpp:1580

Scope: file

Source code excerpt:

static FThreadSafeCounter NotTicked;

static TAutoConsoleVariable<int32> CVarSpewAnimRateOptimization(
	TEXT("SpewAnimRateOptimization"),
	0,
	TEXT("True to spew overall anim rate optimization tick rates."));

void USkeletalMeshComponent::TickPose(float DeltaTime, bool bNeedsValidRootMotion)
{

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/SkeletalMeshComponent.cpp:1609

Scope (from outer to inner):

file
function     void USkeletalMeshComponent::TickPose

Source code excerpt:


		TickAnimation(DeltaTimeForTick, bNeedsValidRootMotion);
		if (CVarSpewAnimRateOptimization.GetValueOnGameThread() > 0 && Ticked.Increment()==500)
		{
			UE_LOG(LogTemp, Display, TEXT("%d Ticked %d NotTicked"), Ticked.GetValue(), NotTicked.GetValue());
			Ticked.Reset();
			NotTicked.Reset();
		}
	}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/SkeletalMeshComponent.cpp:1633

Scope (from outer to inner):

file
function     void USkeletalMeshComponent::TickPose

Source code excerpt:

		}

		if (CVarSpewAnimRateOptimization.GetValueOnGameThread())
		{
			NotTicked.Increment();
		}
	}
}