r.Nanite.ForceEnableMeshes
r.Nanite.ForceEnableMeshes
#Overview
name: r.Nanite.ForceEnableMeshes
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Force enables all meshes to also build Nanite data, regardless of the enabled flag on the asset.
It is referenced in 6
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Nanite.ForceEnableMeshes is to force enable Nanite data generation for all meshes, regardless of the enabled flag set on individual assets. This setting variable is primarily used for the rendering system, specifically for Nanite, which is Unreal Engine 5’s virtualized geometry system.
This setting variable is relied upon by several Unreal Engine subsystems and modules, including:
- The Static Mesh rendering system (StaticMesh.cpp)
- The Material system (Material.cpp and MaterialShared.cpp)
- The Nanite rendering system (NaniteResources.cpp)
The value of this variable is set as a console variable with a default value of 0 (disabled). It can be changed at runtime through the console or configuration files.
This variable interacts with the bForceNaniteUsage flag in the Material class and affects the behavior of IsUsedWithNanite() function in the FMaterialResource class. It also influences the material auditing process for Nanite.
Developers must be aware that enabling this variable will force Nanite data generation for all meshes, which may increase memory usage and build times. It should be used carefully, primarily for testing or debugging purposes.
Best practices when using this variable include:
- Only enable it when necessary for testing or debugging.
- Be aware of the potential performance impact on build times and memory usage.
- Ensure that the project has sufficient resources to handle the increased data generation.
The associated variable CVarForceEnableNaniteMeshes is the actual console variable that stores the value of r.Nanite.ForceEnableMeshes. It is defined as a TAutoConsoleVariable
The purpose of CVarForceEnableNaniteMeshes is to provide a runtime-accessible way to check if Nanite should be force-enabled for all meshes. It is used in the UStaticMesh::IsNaniteForceEnabled() function to determine if Nanite should be forced on for a specific static mesh.
When working with CVarForceEnableNaniteMeshes, developers should:
- Use the GetValueOnAnyThread() method to safely access its value from any thread.
- Be aware that changes to this variable will affect all meshes in the project.
- Consider the performance implications of enabling this feature globally.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMesh.cpp:159
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarForceEnableNaniteMeshes(
TEXT("r.Nanite.ForceEnableMeshes"),
0,
TEXT("Force enables all meshes to also build Nanite data, regardless of the enabled flag on the asset."),
ECVF_ReadOnly | ECVF_RenderThreadSafe);
#if ENABLE_COOK_STATS
namespace StaticMeshCookStats
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Materials/Material.cpp:2866
Scope (from outer to inner):
file
function void UMaterial::Serialize
Source code excerpt:
if (Ar.IsSaving() && Ar.IsCooking() && Ar.IsPersistent() && !Ar.IsObjectReferenceCollector())
{
static auto NaniteForceEnableMeshesCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Nanite.ForceEnableMeshes"));
static bool bForceNaniteUsageValue = (NaniteForceEnableMeshesCVar && NaniteForceEnableMeshesCVar->GetValueOnAnyThread() != 0);
bForceNaniteUsage = bForceNaniteUsageValue;
}
Ar << bForceNaniteUsage;
if (Ar.IsLoading() && bForceNaniteUsage)
{
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Materials/MaterialShared.cpp:1864
Scope (from outer to inner):
file
function bool FMaterialResource::IsUsedWithNanite
Source code excerpt:
}
static const auto NaniteForceEnableMeshesCvar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Nanite.ForceEnableMeshes"));
static const bool bNaniteForceEnableMeshes = NaniteForceEnableMeshesCvar && NaniteForceEnableMeshesCvar->GetValueOnAnyThread() != 0;
if (bNaniteForceEnableMeshes)
{
const bool bIsInGameThread = (IsInGameThread() || IsInParallelGameThread());
const FMaterialShaderMap* ShaderMap = bIsInGameThread ? GetGameThreadShaderMap() : GetRenderingThreadShaderMap();
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Rendering/NaniteResources.cpp:2204
Scope (from outer to inner):
file
namespace Nanite
function FMaterialAudit& AuditMaterialsImp
Source code excerpt:
FMaterialAudit& AuditMaterialsImp(const T* InProxyDesc, FMaterialAudit& Audit, bool bSetMaterialUsage)
{
static const auto NaniteForceEnableMeshesCvar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Nanite.ForceEnableMeshes"));
static const bool bNaniteForceEnableMeshes = NaniteForceEnableMeshesCvar && NaniteForceEnableMeshesCvar->GetValueOnAnyThread() != 0;
Audit.bHasAnyError = false;
Audit.Entries.Reset();
if (InProxyDesc != nullptr)
#Associated Variable and Callsites
This variable is associated with another variable named CVarForceEnableNaniteMeshes
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMesh.cpp:158
Scope: file
Source code excerpt:
ECVF_Scalability);
static TAutoConsoleVariable<int32> CVarForceEnableNaniteMeshes(
TEXT("r.Nanite.ForceEnableMeshes"),
0,
TEXT("Force enables all meshes to also build Nanite data, regardless of the enabled flag on the asset."),
ECVF_ReadOnly | ECVF_RenderThreadSafe);
#if ENABLE_COOK_STATS
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMesh.cpp:8694
Scope (from outer to inner):
file
function bool UStaticMesh::IsNaniteForceEnabled
Source code excerpt:
bool UStaticMesh::IsNaniteForceEnabled() const
{
static const bool bForceEnabled = !!CVarForceEnableNaniteMeshes.GetValueOnAnyThread();
return bForceEnabled;
}
#endif
/*-----------------------------------------------------------------------------