r.Nanite.MaterialOverrides
r.Nanite.MaterialOverrides
#Overview
name: r.Nanite.MaterialOverrides
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Enable support for Nanite specific material overrides.
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Nanite.MaterialOverrides is to enable support for Nanite-specific material overrides in Unreal Engine 5. This setting variable is primarily used in the rendering system, specifically for the Nanite virtualized geometry system.
The Unreal Engine subsystem that relies on this setting variable is primarily the rendering system, particularly the Nanite subsystem. It’s used in the StaticMeshRender and StaticMeshComponent modules.
The value of this variable is set through a console variable (CVar) named “r.Nanite.MaterialOverrides”. It’s initialized with a default value of 1, meaning Nanite material overrides are enabled by default.
The associated variable GEnableNaniteMaterialOverrides interacts directly with r.Nanite.MaterialOverrides. They share the same value, and GEnableNaniteMaterialOverrides is used in the C++ code to check if Nanite material overrides are enabled.
Developers must be aware that changing this variable will trigger a recreation of render states for components. This is evident from the FGlobalComponentRecreateRenderStateContext being created when the console variable changes.
Best practices when using this variable include:
- Be cautious when disabling it, as it might affect the rendering of Nanite-enabled static meshes.
- If you’re creating custom rendering code that interacts with Nanite, check the value of GEnableNaniteMaterialOverrides to ensure compatibility.
- Be aware that changing this setting at runtime will have performance implications due to the recreation of render states.
Regarding the associated variable GEnableNaniteMaterialOverrides:
The purpose of GEnableNaniteMaterialOverrides is to provide a C++-accessible flag for whether Nanite material overrides are enabled.
It’s used in the StaticMeshComponent module to determine if Nanite override materials should be used. Specifically, it’s checked in the UseNaniteOverrideMaterials function.
The value of this variable is set by the r.Nanite.MaterialOverrides console variable.
This variable interacts directly with r.Nanite.MaterialOverrides, serving as its C++ representation.
Developers should be aware that this variable is used in conditional checks to determine whether to use Nanite override materials. Changes to this variable will affect how static meshes are rendered with Nanite.
Best practices include:
- Use this variable in any custom rendering code that needs to be aware of Nanite material override settings.
- Remember that this variable is affected by the r.Nanite.MaterialOverrides console command, so it can be changed at runtime.
- Consider the performance implications of frequently checking or changing this variable, as it can trigger render state updates.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMeshRender.cpp:108
Scope: file
Source code excerpt:
int32 GEnableNaniteMaterialOverrides = 1;
FAutoConsoleVariableRef CVarEnableNaniteNaterialOverrides(
TEXT("r.Nanite.MaterialOverrides"),
GEnableNaniteMaterialOverrides,
TEXT("Enable support for Nanite specific material overrides."),
FConsoleVariableDelegate::CreateLambda([](IConsoleVariable* InVariable)
{
FGlobalComponentRecreateRenderStateContext Context;
}),
#Associated Variable and Callsites
This variable is associated with another variable named GEnableNaniteMaterialOverrides
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/StaticMeshComponent.cpp:56
Scope: file
Source code excerpt:
DECLARE_MEMORY_STAT( TEXT( "StaticMesh PreCulled Index Memory" ), STAT_StaticMeshPreCulledIndexMemory, STATGROUP_MemoryStaticMesh );
extern int32 GEnableNaniteMaterialOverrides;
FStaticMeshComponentInstanceData::FStaticMeshComponentInstanceData(const UStaticMeshComponent* SourceComponent)
: FPrimitiveComponentInstanceData(SourceComponent)
, StaticMesh(SourceComponent->GetStaticMesh())
{
for (const FStaticMeshComponentLODInfo& LODDataEntry : SourceComponent->LODData)
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/StaticMeshComponent.cpp:2373
Scope (from outer to inner):
file
namespace Nanite
function bool UseNaniteOverrideMaterials
Source code excerpt:
{
// Check for valid data on this SMC and support for Nanite material overrides
return (bDoingMaterialAudit || ShouldCreateNaniteProxy(Component, nullptr)) && GEnableNaniteMaterialOverrides != 0;
}
}
bool UStaticMeshComponent::HasValidNaniteData() const
{
return Nanite::HasValidNaniteData(*this);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMeshRender.cpp:106
Scope: file
Source code excerpt:
// TODO: Should move this outside of SM, since Nanite can be used for multiple primitive types
int32 GEnableNaniteMaterialOverrides = 1;
FAutoConsoleVariableRef CVarEnableNaniteNaterialOverrides(
TEXT("r.Nanite.MaterialOverrides"),
GEnableNaniteMaterialOverrides,
TEXT("Enable support for Nanite specific material overrides."),
FConsoleVariableDelegate::CreateLambda([](IConsoleVariable* InVariable)
{
FGlobalComponentRecreateRenderStateContext Context;
}),
ECVF_Scalability | ECVF_RenderThreadSafe