r.InstanceData.MinInstanceCountToOptimize
r.InstanceData.MinInstanceCountToOptimize
#Overview
name: r.InstanceData.MinInstanceCountToOptimize
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Minimum number of instances to perform optimized build for (if enabled), can be used to disable optimized build for small ISMs as there is some overhead from doing so.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.InstanceData.MinInstanceCountToOptimize is to set the minimum number of instances required to perform an optimized build for Instanced Static Meshes (ISMs) in Unreal Engine 5. This setting is part of the rendering system, specifically for optimizing the performance of instanced static meshes.
This setting variable is primarily used in the Engine module, particularly in the Instanced Static Mesh system. Based on the callsites, it’s utilized in the ISMInstanceDataManager.cpp file, which is responsible for managing instance data for static meshes.
The value of this variable is set using a console variable (CVar) system. It’s initialized with a default value of 2, but can be modified at runtime or through configuration files.
The associated variable CVarInstanceDataMinInstanceCountToOptimize directly interacts with r.InstanceData.MinInstanceCountToOptimize. They share the same value and purpose.
Developers should be aware that this variable affects the performance optimization of Instanced Static Meshes. Setting this value too low might cause unnecessary overhead for small ISMs, while setting it too high might prevent optimization for ISMs that could benefit from it.
Best practices when using this variable include:
- Carefully consider the default value (2) and adjust it based on your project’s specific needs and performance characteristics.
- Monitor performance metrics when changing this value to ensure it’s providing the desired optimization.
- Be mindful that very small ISMs might not benefit from optimization due to the overhead involved.
Regarding the associated variable CVarInstanceDataMinInstanceCountToOptimize:
- It’s the actual console variable that controls the minimum instance count for optimization.
- It’s used in the ShouldWriteCookedData function to determine if cooked data should be written for a given number of instances.
- Developers can access and modify this value at runtime using console commands or through C++ code.
- When adjusting this value, consider the impact on both runtime performance and cooking/build times for your project.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh/ISMInstanceDataManager.cpp:37
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarInstanceDataMinInstanceCountToOptimize(
TEXT("r.InstanceData.MinInstanceCountToOptimize"),
2,
TEXT("Minimum number of instances to perform optimized build for (if enabled), can be used to disable optimized build for small ISMs as there is some overhead from doing so."));
namespace RenderingSpatialHash
{
template <typename ScalarType>
#Associated Variable and Callsites
This variable is associated with another variable named CVarInstanceDataMinInstanceCountToOptimize
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh/ISMInstanceDataManager.cpp:36
Scope: file
Source code excerpt:
TEXT("Chicken switch to disable the new code to reset tracking & instance count during OnRegister, if this causes problems.\nTODO: Remove."));
static TAutoConsoleVariable<int32> CVarInstanceDataMinInstanceCountToOptimize(
TEXT("r.InstanceData.MinInstanceCountToOptimize"),
2,
TEXT("Minimum number of instances to perform optimized build for (if enabled), can be used to disable optimized build for small ISMs as there is some overhead from doing so."));
namespace RenderingSpatialHash
{
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh/ISMInstanceDataManager.cpp:1085
Scope (from outer to inner):
file
function bool FPrimitiveInstanceDataManager::ShouldWriteCookedData
Source code excerpt:
return bValidTypeAndMobility
&& NumInstancesToBuildFor >= CVarInstanceDataMinInstanceCountToOptimize.GetValueOnAnyThread()
&& ShouldUsePrecomputed()
&& DoesTargetPlatformSupportNanite(TargetPlatform);
}
void FPrimitiveInstanceDataManager::BeginCacheForCookedPlatformData(const ITargetPlatform* TargetPlatform, FInstanceUpdateComponentDesc &&ComponentData, TStridedView<FMatrix> InstanceTransforms)