p.BasedMovementMode

p.BasedMovementMode

#Overview

name: p.BasedMovementMode

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

It is referenced in 6 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.BasedMovementMode is to control how and when based movement updates are performed for characters in Unreal Engine 5. This setting variable is primarily used in the character movement system.

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 changed at runtime through console commands. The default value is 2.

The associated variable BasedMovementMode interacts directly with p.BasedMovementMode. They share the same value and are used interchangeably in the code.

Developers must be aware that this variable affects the timing and frequency of based movement updates. The possible values are: 0: Always update on regular tick (default behavior before the implementation of this feature) 1: Update only if not deferring updates 2: Update and save based movement both on regular ticks and post physics when on a physics base

The best practices when using this variable include:

  1. Consider the performance implications of each mode. Mode 2 might be more accurate but could be more computationally expensive.
  2. Test thoroughly when changing this value, as it can significantly affect character movement behavior, especially on moving platforms or vehicles.
  3. Be cautious when changing this value at runtime, as it may lead to unexpected behavior if not properly handled.

Regarding the associated variable BasedMovementMode: The purpose of BasedMovementMode is the same as p.BasedMovementMode, as they share the same value. It is used directly in the Character Movement Component’s code to determine how based movement should be handled. The value is set through the console variable p.BasedMovementMode. It interacts with various functions in the CharacterMovementComponent, such as SimulateMovement, MaybeUpdateBasedMovement, MaybeSaveBaseLocation, and PerformMovement. Developers should be aware that changing BasedMovementMode will affect all these functions and potentially the overall character movement behavior. Best practices include thoroughly testing any changes to this variable and considering its impact on performance and gameplay feel.

#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:243

Scope (from outer to inner):

file
namespace    CharacterMovementCVars

Source code excerpt:

	int32 BasedMovementMode = 2;
	FAutoConsoleVariableRef CVarBasedMovementMode(
		TEXT("p.BasedMovementMode"),
		BasedMovementMode, TEXT("0 means always on regular tick (default); 1 means only if not deferring updates; 2 means update and save based movement both on regular ticks and post physics when on a physics base."));

	/**
	 * Option to handle move acceleration as relative to dynamic movement bases. If disabled, moves are handled in world space.
	 * Enabling this will produce better motion when walking on highly dynamic / unpredictable movement bases, such as vehicles. However, there is the potential for larger corrections when landing on or jumping off if the base's rotation is not well-sync'd.
	 * This also may be a good option if using dynamic movement bases that become the player's primary frame of visual reference, such as when walking on a large boat or airship.

#Associated Variable and Callsites

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

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

Scope (from outer to inner):

file
namespace    CharacterMovementCVars

Source code excerpt:

		AsyncCharacterMovement, TEXT("1 enables asynchronous simulation of character movement on physics thread. Toggling this at runtime is not recommended. This feature is not fully developed, and its use is discouraged."));

	int32 BasedMovementMode = 2;
	FAutoConsoleVariableRef CVarBasedMovementMode(
		TEXT("p.BasedMovementMode"),
		BasedMovementMode, TEXT("0 means always on regular tick (default); 1 means only if not deferring updates; 2 means update and save based movement both on regular ticks and post physics when on a physics base."));

	/**
	 * Option to handle move acceleration as relative to dynamic movement bases. If disabled, moves are handled in world space.
	 * Enabling this will produce better motion when walking on highly dynamic / unpredictable movement bases, such as vehicles. However, there is the potential for larger corrections when landing on or jumping off if the base's rotation is not well-sync'd.
	 * This also may be a good option if using dynamic movement bases that become the player's primary frame of visual reference, such as when walking on a large boat or airship.
	 * Not compatible with deprecated move RPCs. @see NetUsePackedMovementRPCs

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

Scope (from outer to inner):

file
function     void UCharacterMovementComponent::SimulateMovement

Source code excerpt:

	CallMovementUpdateDelegate(DeltaSeconds, OldLocation, OldVelocity);

	if (CharacterMovementCVars::BasedMovementMode == 0)
	{
		SaveBaseLocation(); // behaviour before implementing this fix
	}
	else
	{
		MaybeSaveBaseLocation();

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

Scope (from outer to inner):

file
function     void UCharacterMovementComponent::MaybeUpdateBasedMovement

Source code excerpt:

			}

			if (CharacterMovementCVars::BasedMovementMode == 2)
			{
				UpdateBasedMovement(DeltaSeconds);
			}
		}
	}
	else

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

Scope (from outer to inner):

file
function     void UCharacterMovementComponent::MaybeSaveBaseLocation

Source code excerpt:

void UCharacterMovementComponent::MaybeSaveBaseLocation()
{
	if (CharacterMovementCVars::BasedMovementMode == 2 || !bDeferUpdateBasedMovement)
	{
		SaveBaseLocation();
	}
}

// @todo handle lift moving up and down through encroachment

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

Scope (from outer to inner):

file
function     void UCharacterMovementComponent::PerformMovement

Source code excerpt:

	CallMovementUpdateDelegate(DeltaSeconds, OldLocation, OldVelocity);

	if (CharacterMovementCVars::BasedMovementMode == 0)
	{
		SaveBaseLocation(); // behaviour before implementing this fix
	}
	else
	{
		MaybeSaveBaseLocation();