landscape.SimulatePhysics

landscape.SimulatePhysics

#Overview

name: landscape.SimulatePhysics

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 landscape.SimulatePhysics is to enable physics simulation on worlds containing landscapes in Unreal Engine 5. This setting is primarily related to the landscape system and physics simulation.

The Unreal Engine subsystem that relies on this setting variable is the Landscape module, as evidenced by its location in the LandscapeEditLayers.cpp file.

The value of this variable is set using a console variable (CVar) system. It is initialized with a default value of 0, meaning physics simulation is disabled by default for landscapes.

The associated variable CVarLandscapeSimulatePhysics interacts directly with landscape.SimulatePhysics. They share the same value and purpose.

Developers must be aware that:

  1. This variable is intended for use in non-Play-In-Editor (PIE) scenarios.
  2. Enabling this variable will affect the entire world’s physics simulation, not just the landscape.
  3. It’s a runtime setting that can be changed dynamically.

Best practices when using this variable include:

  1. Use it cautiously, as enabling physics simulation for landscapes can be computationally expensive.
  2. Consider the performance implications, especially for large or complex landscapes.
  3. Test thoroughly in non-PIE scenarios to ensure desired behavior.
  4. Use it primarily for debugging or specific gameplay scenarios that require landscape physics simulation.

Regarding the associated variable CVarLandscapeSimulatePhysics:

The purpose of CVarLandscapeSimulatePhysics is to provide programmatic access to the landscape.SimulatePhysics setting within the C++ code.

It is used within the ALandscape::TickLayers function to check if physics simulation should be enabled for the world containing the landscape.

The value of this variable is set through the console variable system, just like landscape.SimulatePhysics.

CVarLandscapeSimulatePhysics directly controls the World->bShouldSimulatePhysics flag when its value is 1.

Developers should be aware that this variable is checked on any thread (GetValueOnAnyThread()), which means it can potentially be accessed from multiple threads simultaneously.

Best practices for using CVarLandscapeSimulatePhysics include:

  1. Use it for runtime checks rather than compile-time decisions.
  2. Be cautious about changing its value during gameplay, as it affects the entire world’s physics simulation.
  3. Consider potential performance impacts when enabling it, especially in shipping builds.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Landscape/Private/LandscapeEditLayers.cpp:116

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarLandscapeSimulatePhysics(
	TEXT("landscape.SimulatePhysics"),
	0,
	TEXT("This will enable physic simulation on worlds containing landscape."));

static TAutoConsoleVariable<int32> CVarLandscapeLayerOptim(
	TEXT("landscape.Optim"),
	1,

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Landscape/Private/LandscapeEditLayers.cpp:115

Scope: file

Source code excerpt:

	TEXT("This will output the content of render target used for weightmap. This is used for debugging only."));

static TAutoConsoleVariable<int32> CVarLandscapeSimulatePhysics(
	TEXT("landscape.SimulatePhysics"),
	0,
	TEXT("This will enable physic simulation on worlds containing landscape."));

static TAutoConsoleVariable<int32> CVarLandscapeLayerOptim(
	TEXT("landscape.Optim"),

#Loc: <Workspace>/Engine/Source/Runtime/Landscape/Private/LandscapeEditLayers.cpp:8702

Scope (from outer to inner):

file
function     void ALandscape::TickLayers

Source code excerpt:

	if (World && !World->IsPlayInEditor() && GetLandscapeInfo() && GEditor->PlayWorld == nullptr)
	{
		if (CVarLandscapeSimulatePhysics.GetValueOnAnyThread() == 1)
		{
			World->bShouldSimulatePhysics = true;
		}

		UpdateLayersContent();
	}