r.InstancedStaticMeshes.AllowCreateEmpty

r.InstancedStaticMeshes.AllowCreateEmpty

#Overview

name: r.InstancedStaticMeshes.AllowCreateEmpty

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 r.InstancedStaticMeshes.AllowCreateEmpty is to control whether empty Instanced Static Meshes (ISMs) can be created in Unreal Engine 5. This setting is primarily related to the rendering and performance optimization systems.

This setting variable is used in the Engine module, specifically in the Instanced Static Mesh component implementation. It’s primarily relied upon by the rendering and scene management subsystems of Unreal Engine.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 0, meaning that by default, empty ISMs are not allowed to be created.

The associated variable CVarAllowCreateEmptyISMs directly interacts with r.InstancedStaticMeshes.AllowCreateEmpty. They share the same value and purpose.

Developers must be aware that this variable affects the creation of Instanced Static Meshes. When set to 0 (default), attempts to create empty ISMs will fail. When set to 1, empty ISMs can be created.

Best practices when using this variable include:

  1. Only enable it when absolutely necessary, as empty ISMs might impact performance or cause unexpected behavior in rendering or gameplay systems.
  2. Be cautious when enabling this in production builds, as it might lead to visual artifacts or performance issues if misused.
  3. Use it in conjunction with proper error handling and validation in your code to ensure robustness.

Regarding the associated variable CVarAllowCreateEmptyISMs:

The purpose of CVarAllowCreateEmptyISMs is identical to r.InstancedStaticMeshes.AllowCreateEmpty. It’s the actual C++ variable that controls the behavior described above.

This variable is used in the Engine module, specifically in the Instanced Static Mesh component implementation.

The value of CVarAllowCreateEmptyISMs is set through the CVar system and can be changed at runtime.

It directly interacts with the r.InstancedStaticMeshes.AllowCreateEmpty console variable, as they represent the same setting.

Developers should be aware that this variable is checked in the code that validates whether an Instanced Static Mesh can be created. If the number of instances is zero and this variable is false, the ISM creation will fail.

Best practices for using CVarAllowCreateEmptyISMs include:

  1. Access its value using the GetValueOnGameThread() method to ensure thread-safe access.
  2. Consider the performance implications of allowing empty ISMs before enabling this feature.
  3. Use this variable in conjunction with other validation checks to ensure the integrity of your Instanced Static Meshes.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:90

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarAllowCreateEmptyISMs(
	TEXT("r.InstancedStaticMeshes.AllowCreateEmpty"),
	0,
	TEXT("Whether to allow creation of empty ISMS."));

TAutoConsoleVariable<int32> CVarMinLOD(
	TEXT("foliage.MinLOD"),
	-1,

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:89

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarAllowCreateEmptyISMs(
	TEXT("r.InstancedStaticMeshes.AllowCreateEmpty"),
	0,
	TEXT("Whether to allow creation of empty ISMS."));

TAutoConsoleVariable<int32> CVarMinLOD(
	TEXT("foliage.MinLOD"),

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:2236

Scope: file

Source code excerpt:

#endif
		// make sure we have instances - or have explicitly permitted creating emtpty ISMs
		(PerInstanceSMData.Num() > 0 || CVarAllowCreateEmptyISMs.GetValueOnGameThread()) &&
		// make sure we have an actual static mesh
		GetStaticMesh() &&
		GetStaticMesh()->IsCompiling() == false &&
		GetStaticMesh()->HasValidRenderData();

	if (!bIsMeshAndInstanceDataValid)