LyraCharacter.GroundTraceDistance

LyraCharacter.GroundTraceDistance

#Overview

name: LyraCharacter.GroundTraceDistance

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 LyraCharacter.GroundTraceDistance is to define the distance for downward tracing when generating ground information for character movement in the Lyra game project. This setting is crucial for the character movement system, specifically for ground detection and interaction.

This setting variable is primarily used in the Lyra game project, specifically within the character movement component. It’s part of the LyraGame module, which is likely a custom module for the Lyra project built on top of Unreal Engine 5.

The value of this variable is set initially as a static float with a value of 100000.0f. It’s then associated with a console variable (CVar) named “LyraCharacter.GroundTraceDistance” using FAutoConsoleVariableRef. This allows the value to be changed at runtime through the console, which is useful for debugging and tweaking.

The associated variable GroundTraceDistance interacts directly with LyraCharacter.GroundTraceDistance. They share the same value, with GroundTraceDistance being the actual variable used in the code, while LyraCharacter.GroundTraceDistance is the console-accessible name.

Developers must be aware that this variable affects the ground detection for characters. A very large value (like the default 100000.0f) ensures that ground will almost always be detected, but might be unnecessarily computationally expensive. A too small value might cause characters to fail to detect ground properly in certain scenarios.

Best practices when using this variable include:

  1. Adjusting it to an appropriate value that balances accuracy and performance for your specific game world.
  2. Using the console variable for real-time tweaking during development and testing.
  3. Consider exposing it as a configurable setting if different levels or game modes require different values.

Regarding the associated variable GroundTraceDistance: The purpose of GroundTraceDistance is to store the actual value used in the character movement calculations. It’s used directly in the GetGroundInfo() function of the ULyraCharacterMovementComponent to determine the end point of the ground trace.

This variable is set and used within the LyraGame module, specifically in the character movement component. Its value is initially set to 100000.0f and can be modified through the console variable system.

GroundTraceDistance interacts directly with the console variable LyraCharacter.GroundTraceDistance. Any changes to the console variable will affect this variable.

Developers should be aware that this variable directly impacts the ground detection logic. It’s used to calculate the trace end point and to set the GroundDistance in the cached ground info.

Best practices for using GroundTraceDistance include:

  1. Ensuring it’s properly synchronized with the console variable.
  2. Considering performance implications when setting its value, as very large values might lead to unnecessary long traces.
  3. Testing thoroughly with different values to ensure robust ground detection across all potential game scenarios.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Projects/Lyra/Source/LyraGame/Character/LyraCharacterMovementComponent.cpp:15

Scope (from outer to inner):

file
namespace    LyraCharacter

Source code excerpt:

{
	static float GroundTraceDistance = 100000.0f;
	FAutoConsoleVariableRef CVar_GroundTraceDistance(TEXT("LyraCharacter.GroundTraceDistance"), GroundTraceDistance, TEXT("Distance to trace down when generating ground information."), ECVF_Cheat);
};


ULyraCharacterMovementComponent::ULyraCharacterMovementComponent(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{

#Associated Variable and Callsites

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

#Loc: <Workspace>/Projects/Lyra/Source/LyraGame/Character/LyraCharacterMovementComponent.cpp:14

Scope (from outer to inner):

file
namespace    LyraCharacter

Source code excerpt:

namespace LyraCharacter
{
	static float GroundTraceDistance = 100000.0f;
	FAutoConsoleVariableRef CVar_GroundTraceDistance(TEXT("LyraCharacter.GroundTraceDistance"), GroundTraceDistance, TEXT("Distance to trace down when generating ground information."), ECVF_Cheat);
};


ULyraCharacterMovementComponent::ULyraCharacterMovementComponent(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{

#Loc: <Workspace>/Projects/Lyra/Source/LyraGame/Character/LyraCharacterMovementComponent.cpp:71

Scope (from outer to inner):

file
function     const FLyraCharacterGroundInfo& ULyraCharacterMovementComponent::GetGroundInfo

Source code excerpt:

		const ECollisionChannel CollisionChannel = (UpdatedComponent ? UpdatedComponent->GetCollisionObjectType() : ECC_Pawn);
		const FVector TraceStart(GetActorLocation());
		const FVector TraceEnd(TraceStart.X, TraceStart.Y, (TraceStart.Z - LyraCharacter::GroundTraceDistance - CapsuleHalfHeight));

		FCollisionQueryParams QueryParams(SCENE_QUERY_STAT(LyraCharacterMovementComponent_GetGroundInfo), false, CharacterOwner);
		FCollisionResponseParams ResponseParam;
		InitCollisionParams(QueryParams, ResponseParam);

		FHitResult HitResult;

#Loc: <Workspace>/Projects/Lyra/Source/LyraGame/Character/LyraCharacterMovementComponent.cpp:81

Scope (from outer to inner):

file
function     const FLyraCharacterGroundInfo& ULyraCharacterMovementComponent::GetGroundInfo

Source code excerpt:


		CachedGroundInfo.GroundHitResult = HitResult;
		CachedGroundInfo.GroundDistance = LyraCharacter::GroundTraceDistance;

		if (MovementMode == MOVE_NavWalking)
		{
			CachedGroundInfo.GroundDistance = 0.0f;
		}
		else if (HitResult.bBlockingHit)