r.MaterialEditor.MaxDerivedMaterialInstances

r.MaterialEditor.MaxDerivedMaterialInstances

#Overview

name: r.MaterialEditor.MaxDerivedMaterialInstances

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.MaterialEditor.MaxDerivedMaterialInstances is to limit the number of derived material instances shown in platform statistics within the Material Editor. This setting is part of Unreal Engine’s material system and is specifically used in the Material Editor module.

The Unreal Engine subsystem that relies on this setting variable is the Material Editor, which is part of the editor toolset. It’s used within the MaterialEditor module, as evidenced by its implementation in the MaterialEditor.cpp file.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of -1, which means there’s no limit by default. Users can change this value at runtime through console commands or configuration files.

This variable interacts with the associated variable CVarMaterialEdMaxDerivedMaterialInstances. They share the same value and purpose, with CVarMaterialEdMaxDerivedMaterialInstances being the actual TAutoConsoleVariable instance used in the code.

Developers must be aware that:

  1. Changing this value at runtime requires reopening the Material Editor to take effect.
  2. A negative value disables the limit entirely.
  3. This limit affects the platform statistics view, not the actual number of derived instances that can be created.

Best practices when using this variable include:

  1. Set a reasonable limit if performance issues are observed with many derived instances.
  2. Consider the trade-off between comprehensive statistics and editor performance when adjusting this value.
  3. Communicate changes to this value to the entire development team, as it affects the Material Editor’s behavior.

Regarding the associated variable CVarMaterialEdMaxDerivedMaterialInstances:

This is the actual console variable instance used in the code to implement the r.MaterialEditor.MaxDerivedMaterialInstances setting. It’s used directly in the CreateDerivedMaterialInstancesPreviews function of the FMaterialEditor class to limit the number of derived material instances processed for preview.

Developers should be aware that:

  1. This variable is accessed using GetValueOnGameThread(), indicating it’s safe to read from the game thread.
  2. The value is used as an upper bound in a loop iterating over UMaterialInstance objects.

Best practices for using CVarMaterialEdMaxDerivedMaterialInstances include:

  1. Access the value through the GetValueOnGameThread() method when used in game thread contexts.
  2. Consider caching the value if it’s used frequently, as console variable access can have some overhead.
  3. Be mindful of the performance implications when setting this to a high value or -1 (unlimited), especially in projects with many material instances.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Editor/MaterialEditor/Private/MaterialEditor.cpp:187

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarMaterialEdMaxDerivedMaterialInstances(
	TEXT("r.MaterialEditor.MaxDerivedMaterialInstances"),
	-1,
	TEXT("Limits amount of derived material instance shown in platform stats. Use negative number to disable the limit. Material editor must be re-opened if changed at runtime."));

TAutoConsoleVariable<bool> CVarMaterialEdAllowIgnoringCompilationErrors(
	TEXT("r.MaterialEditor.AllowIgnoringCompilationErrors"),
	true,

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Editor/MaterialEditor/Private/MaterialEditor.cpp:186

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarMaterialEdMaxDerivedMaterialInstances(
	TEXT("r.MaterialEditor.MaxDerivedMaterialInstances"),
	-1,
	TEXT("Limits amount of derived material instance shown in platform stats. Use negative number to disable the limit. Material editor must be re-opened if changed at runtime."));

TAutoConsoleVariable<bool> CVarMaterialEdAllowIgnoringCompilationErrors(
	TEXT("r.MaterialEditor.AllowIgnoringCompilationErrors"),

#Loc: <Workspace>/Engine/Source/Editor/MaterialEditor/Private/MaterialEditor.cpp:6460

Scope (from outer to inner):

file
function     void FMaterialEditor::CreateDerivedMaterialInstancesPreviews

Source code excerpt:

	if (MaterialStatsManager->GetProvideDerivedMIFlag())
	{
		const int32 MaxCount = CVarMaterialEdMaxDerivedMaterialInstances.GetValueOnGameThread();
		// TODO consider a mode where we load all MaterialChildList also

		for (TObjectIterator<UMaterialInstance> It; It; ++It)
		{
			UMaterialInstance* Instance = *It;
			if (!Instance->HasStaticParameters())