p.NetUseBaseRelativeAcceleration

p.NetUseBaseRelativeAcceleration

#Overview

name: p.NetUseBaseRelativeAcceleration

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

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.NetUseBaseRelativeAcceleration is to control how character acceleration is treated in relation to dynamic movement bases in networked gameplay. This setting variable is primarily used for the character movement system in Unreal Engine 5.

The Unreal Engine subsystem that relies on this setting variable is the Character Movement Component, which is part of the Engine module. This can be seen from the file path where the variable is defined and used: Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp.

The value of this variable is set using an FAutoConsoleVariableRef, which means it can be modified at runtime through console commands. By default, it is set to 1 (enabled).

This variable interacts closely with another variable called NetUseBaseRelativeVelocity, which is defined right after it in the source code. Both variables are used to control how character movement is handled relative to dynamic bases.

Developers must be aware that when this variable is enabled (set to 1), character acceleration will be treated as relative to dynamic movement bases. This can affect how character movement is calculated and replicated in networked games, especially when characters are standing on moving platforms or other dynamic objects.

Best practices when using this variable include:

  1. Ensure consistency across all networked instances of the game to avoid desynchronization issues.
  2. Test thoroughly with various dynamic movement base scenarios to ensure desired behavior.
  3. Consider the performance implications of using base-relative calculations, especially in scenarios with many characters on dynamic bases.

Regarding the associated variable NetUseBaseRelativeAcceleration:

This is the actual integer variable that stores the value controlled by the p.NetUseBaseRelativeAcceleration console variable. It is used in several places within the CharacterMovementComponent to determine whether to use base-relative acceleration calculations.

The purpose of NetUseBaseRelativeAcceleration is to provide a quick, runtime-accessible flag for enabling or disabling base-relative acceleration calculations. It’s used in functions like ClientFillNetworkMoveData, ServerMove_PerformMovement, and FSavedMove_Character::PostUpdate to determine whether acceleration should be transformed between local and world space when dealing with dynamic movement bases.

Developers should be aware that changing this variable at runtime will immediately affect how character movement is calculated and replicated, which could lead to sudden changes in character behavior if not managed carefully.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:254

Scope (from outer to inner):

file
namespace    CharacterMovementCVars

Source code excerpt:

	static int32 NetUseBaseRelativeAcceleration = 1;
	FAutoConsoleVariableRef CVarNetUseBaseRelativeAcceleration(
		TEXT("p.NetUseBaseRelativeAcceleration"),
		NetUseBaseRelativeAcceleration,
		TEXT("If enabled, character acceleration will be treated as relative to dynamic movement bases."));

	static int32 NetUseBaseRelativeVelocity = 1;
	FAutoConsoleVariableRef CVarNetUseBaseRelativeVelocity(
		TEXT("p.NetUseBaseRelativeVelocity"),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:252

Scope (from outer to inner):

file
namespace    CharacterMovementCVars

Source code excerpt:

	 * Not compatible with deprecated move RPCs. @see NetUsePackedMovementRPCs
	 */
	static int32 NetUseBaseRelativeAcceleration = 1;
	FAutoConsoleVariableRef CVarNetUseBaseRelativeAcceleration(
		TEXT("p.NetUseBaseRelativeAcceleration"),
		NetUseBaseRelativeAcceleration,
		TEXT("If enabled, character acceleration will be treated as relative to dynamic movement bases."));

	static int32 NetUseBaseRelativeVelocity = 1;
	FAutoConsoleVariableRef CVarNetUseBaseRelativeVelocity(
		TEXT("p.NetUseBaseRelativeVelocity"),
		NetUseBaseRelativeVelocity,

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:9413

Scope (from outer to inner):

file
function     void FCharacterNetworkMoveData::ClientFillNetworkMoveData

Source code excerpt:


	const bool bSendBaseRelativeLocation     = MovementBaseUtility::UseRelativeLocation(ClientMovementBase);
	const bool bSendBaseRelativeAcceleration = CharacterMovementCVars::NetUseBaseRelativeAcceleration && bSendBaseRelativeLocation;

	const FVector SendLocation     = bSendBaseRelativeLocation ? ClientMove.SavedRelativeLocation : FRepMovement::RebaseOntoZeroOrigin(ClientMove.SavedLocation, ClientMove.CharacterOwner->GetCharacterMovement());
	const FVector SendAcceleration = bSendBaseRelativeAcceleration ? ClientMove.SavedRelativeAcceleration : ClientMove.Acceleration;

	Location = SendLocation;
	Acceleration = SendAcceleration;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:9568

Scope (from outer to inner):

file
function     void UCharacterMovementComponent::ServerMove_PerformMovement

Source code excerpt:


	// Convert the move's acceleration to worldspace if necessary
	if (CharacterMovementCVars::NetUseBaseRelativeAcceleration && MovementBaseUtility::IsDynamicBase(MoveData.MovementBase))
	{
		MovementBaseUtility::TransformDirectionToWorld(MoveData.MovementBase, MoveData.MovementBaseBoneName, MoveData.Acceleration, ClientAccel);
	}

	const uint8 ClientMoveFlags = MoveData.CompressedMoveFlags;
	const FRotator ClientControlRotation = MoveData.ControlRotation;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:12265

Scope (from outer to inner):

file
function     void FSavedMove_Character::PostUpdate

Source code excerpt:


		// Save off movement base-relative acceleration if needed
		if (CharacterMovementCVars::NetUseBaseRelativeAcceleration && MovementBaseUtility::IsDynamicBase(MovementBase))
		{
			MovementBaseUtility::TransformDirectionToLocal(EndBase.Get(), EndBoneName, Acceleration, SavedRelativeAcceleration);
		}

		// Attachment state
		if (const USceneComponent* UpdatedComponent = Character->GetCharacterMovement()->UpdatedComponent)