r.Nanite.ProjectEnabled

r.Nanite.ProjectEnabled

#Overview

name: r.Nanite.ProjectEnabled

This variable is created as a Console Variable (cvar).

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Nanite.ProjectEnabled is to control the enablement of Nanite, Unreal Engine’s virtualized geometry system, at the project level. It serves as a main switch for Nanite functionality across platforms that support it.

This setting variable is primarily used by the rendering system in Unreal Engine 5. Based on the callsites, it’s clear that the Renderer module and RenderCore subsystem rely on this variable.

The value of this variable is set through a console variable (CVar) system. It’s initialized to 1 (enabled) by default, but can be changed via project settings or console commands.

The associated variable GNaniteProjectEnabled directly interacts with r.Nanite.ProjectEnabled. They share the same value, with GNaniteProjectEnabled being the C++ variable that the engine code checks against.

Developers must be aware of several important aspects when using this variable:

  1. Changing this setting influences shader permutations and will cause shaders to be recompiled.
  2. It’s marked as read-only and render thread safe, meaning it shouldn’t be changed during runtime.
  3. Disabling Nanite (setting to 0) can reduce the number of shaders, which might be beneficial for certain projects or platforms.
  4. This setting cannot be used to force Nanite on unsupported platforms.

Best practices for using this variable include:

  1. Consider carefully before disabling Nanite, as it’s a core feature of UE5’s rendering capabilities.
  2. If you need to disable Nanite, do so early in the project to avoid shader recompilation issues later.
  3. Be aware that disabling Nanite might impact visual fidelity and performance optimizations that rely on this technology.

Regarding the associated variable GNaniteProjectEnabled: This is the C++ representation of the r.Nanite.ProjectEnabled console variable. It’s used internally by the engine to check whether Nanite is enabled for the project. The DoesPlatformSupportNanite function uses this variable to determine if Nanite should be used on the current platform. Developers should not modify this variable directly, but instead use the r.Nanite.ProjectEnabled console variable or project settings to control Nanite enablement.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp:27

Scope: file

Source code excerpt:

int32 GNaniteProjectEnabled = 1;
FAutoConsoleVariableRef CVarAllowNanite(
	TEXT("r.Nanite.ProjectEnabled"),
	GNaniteProjectEnabled,
	TEXT("This setting allows you to disable Nanite on platforms that support it to reduce the number of shaders. It cannot be used to force Nanite on on unsupported platforms.\n"),
	ECVF_ReadOnly | ECVF_RenderThreadSafe
);

int32 GAllowTranslucencyShadowsInProject = 0;

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:3993

Scope (from outer to inner):

file
lambda-function

Source code excerpt:

						if (bNaniteEnabledButDisabledInProject)
						{
							static const FText Message = NSLOCTEXT("Renderer", "NaniteDisabledForProject", "Nanite is enabled but cannot render, because the project has Nanite disabled in an ini (r.Nanite.ProjectEnabled = 0)");
							Writer.DrawLine(Message);
						}

						if (bShowDemotedLocalMemoryWarning)
						{
							FString String = FString::Printf(TEXT("Video memory has been exhausted (%.3f MB over budget). Expect extremely poor performance."), float(GDemotedLocalMemorySize) / 1048576.0f);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp:25

Scope: file

Source code excerpt:


// This is a per-project main switch for Nanite, that influences the shader permutations compiled. Changing it will cause shaders to be recompiled.
int32 GNaniteProjectEnabled = 1;
FAutoConsoleVariableRef CVarAllowNanite(
	TEXT("r.Nanite.ProjectEnabled"),
	GNaniteProjectEnabled,
	TEXT("This setting allows you to disable Nanite on platforms that support it to reduce the number of shaders. It cannot be used to force Nanite on on unsupported platforms.\n"),
	ECVF_ReadOnly | ECVF_RenderThreadSafe
);

int32 GAllowTranslucencyShadowsInProject = 0;
FAutoConsoleVariableRef CVarAllowTranslucencyShadowsInProject(

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp:1228

Scope (from outer to inner):

file
function     bool DoesPlatformSupportNanite

Source code excerpt:

	if (bCheckForProjectSetting)
	{
		const bool bNaniteSupported = GNaniteProjectEnabled != 0;
		if (UNLIKELY(!bNaniteSupported))
		{
			return false;
		}
	}