p.UseLastGoodRotationDuringCorrection

p.UseLastGoodRotationDuringCorrection

#Overview

name: p.UseLastGoodRotationDuringCorrection

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

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.UseLastGoodRotationDuringCorrection is to improve visual quality during character movement corrections in networked gameplay scenarios, particularly when using options like bOrientToMovement or bUseControllerDesiredRotation that rotate the character over time.

This setting variable is primarily used by the Character Movement Component, which is part of the Engine module in Unreal Engine 5. It specifically affects the network correction behavior of characters in multiplayer games.

The value of this variable is set as a console variable (CVar) in the CharacterMovementComponent.cpp file. It is initialized to 1 (true) by default, meaning the feature is enabled out of the box.

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

Developers must be aware that this variable affects how character rotations are handled during network corrections. When enabled, it will use the last known good rotation if the server doesn’t specify a new rotation during a correction. This can help maintain smoother visual transitions, especially when characters are constantly rotating due to movement orientation or controller input.

Best practices when using this variable include:

  1. Keep it enabled (default setting) for most multiplayer games to ensure smooth visual transitions during network corrections.
  2. If you notice any unexpected behavior in character rotations during network play, you might want to disable this feature temporarily for debugging purposes.
  3. Be aware of its interaction with bOrientRotationToMovement and bUseControllerDesiredRotation settings, as it’s designed to work in conjunction with these options.

Regarding the associated variable bUseLastGoodRotationDuringCorrection:

The purpose of bUseLastGoodRotationDuringCorrection is identical to p.UseLastGoodRotationDuringCorrection, as they share the same value and functionality.

This variable is used internally within the CharacterMovementComponent to check whether the last good rotation should be used during corrections.

The value of this variable is set through the console variable p.UseLastGoodRotationDuringCorrection.

It directly interacts with the character’s rotation correction logic, particularly in the ClientAdjustPosition_Implementation function.

Developers should be aware that this variable is checked in critical network correction code, and changing its value at runtime will immediately affect how character rotations are handled during network updates.

Best practices for this variable are the same as for p.UseLastGoodRotationDuringCorrection, as they are essentially two representations of the same setting.

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

Scope (from outer to inner):

file
namespace    CharacterMovementCVars

Source code excerpt:

	static int32 bUseLastGoodRotationDuringCorrection = 1;
	FAutoConsoleVariableRef CVarUseLastGoodRotationDuringCorrection(
		TEXT("p.UseLastGoodRotationDuringCorrection"),
		bUseLastGoodRotationDuringCorrection,
		TEXT("When enabled, during a correction, restore the last good rotation before re-simulating saved moves if the server didn't specify one. This improves visual quality with options like bOrientToMovement or bUseControllerDesiredRotation that rotate over time."),
		ECVF_Default);

	static int32 bPreventNonVerticalOrientationBlock = 1;
	FAutoConsoleVariableRef CVarPreventNonVerticalOrientationBlock(

#Associated Variable and Callsites

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

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

Scope (from outer to inner):

file
namespace    CharacterMovementCVars

Source code excerpt:

		ECVF_Default);

	static int32 bUseLastGoodRotationDuringCorrection = 1;
	FAutoConsoleVariableRef CVarUseLastGoodRotationDuringCorrection(
		TEXT("p.UseLastGoodRotationDuringCorrection"),
		bUseLastGoodRotationDuringCorrection,
		TEXT("When enabled, during a correction, restore the last good rotation before re-simulating saved moves if the server didn't specify one. This improves visual quality with options like bOrientToMovement or bUseControllerDesiredRotation that rotate over time."),
		ECVF_Default);

	static int32 bPreventNonVerticalOrientationBlock = 1;
	FAutoConsoleVariableRef CVarPreventNonVerticalOrientationBlock(
		TEXT("p.PreventNonVerticalOrientationBlock"),

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

Scope (from outer to inner):

file
function     void UCharacterMovementComponent::ClientAdjustPosition_Implementation

Source code excerpt:


	// Fall back to the last-known good rotation if the server didn't send one
	if (CharacterMovementCVars::bUseLastGoodRotationDuringCorrection
		&& (bOrientRotationToMovement || bUseControllerDesiredRotation)
		&& (!OptionalRotation.IsSet() && ClientData->LastAckedMove.IsValid()))
	{
		OptionalRotation = ClientData->LastAckedMove->SavedRotation;
	}