r.AllowTexture2DArrayCreation

r.AllowTexture2DArrayCreation

#Overview

name: r.AllowTexture2DArrayCreation

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

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.AllowTexture2DArrayCreation is to enable or disable the creation and use of UTexture2DArray assets in Unreal Engine 5. This setting variable is primarily used for the rendering system, specifically for texture management.

This setting variable is primarily used by the Engine and Editor subsystems, particularly in the texture asset creation and material expression handling modules. It’s also referenced in the EngineAssetDefinitions plugin.

The value of this variable is set as a console variable with a default value of 1 (enabled). It can be changed at runtime through console commands.

Other variables that interact with it include CVarAllowTexture2DArrayAssetCreation, which is directly tied to this setting.

Developers must be aware that this variable controls the ability to create and use Texture2DArray assets. When disabled (set to 0), attempts to create these assets will fail, and certain texture-related UI elements and material expressions may not be available.

Best practices when using this variable include:

  1. Ensure it’s enabled if your project relies on Texture2DArray assets.
  2. Be cautious when disabling it, as it may affect existing assets and materials in your project.
  3. Consider performance implications when enabling Texture2DArray creation, as these assets can be more resource-intensive than standard textures.
  4. Use it in conjunction with proper asset management and optimization strategies to balance visual quality and performance.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/Texture2DArray.cpp:43

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarAllowTexture2DArrayAssetCreation(
	TEXT("r.AllowTexture2DArrayCreation"),
	1,
	TEXT("Enable UTexture2DArray assets"),
	ECVF_Default
);

UTexture2DArray* UTexture2DArray::CreateTransient(int32 InSizeX, int32 InSizeY, int32 InArraySize, EPixelFormat InFormat, const FName InName)

#Loc: <Workspace>/Engine/Plugins/Editor/EngineAssetDefinitions/Source/Private/AssetDefinition_Texture2D.cpp:133

Scope (from outer to inner):

file
lambda-function
lambda-function

Source code excerpt:

				if (ClassPathPermissionList->PassesFilter(UTexture2DArray::StaticClass()->GetClassPathName().ToString()))
				{
					static const auto AllowTextureArrayAssetCreationVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.AllowTexture2DArrayCreation"));
					if (AllowTextureArrayAssetCreationVar->GetValueOnGameThread() != 0)
					{
						const TAttribute<FText> Label = LOCTEXT("Texture_Texture2DArray", "Create Texture Array");
						const TAttribute<FText> ToolTip = LOCTEXT("Texture_CreateTexture2DArrayTooltip", "Creates a new texture array.");
						const FSlateIcon Icon = FSlateIcon(FAppStyle::GetAppStyleSetName(), "ClassIcon.Texture2D");
						const FToolMenuExecuteAction UIAction = FToolMenuExecuteAction::CreateStatic(&ExecuteCreateTextureArray);

						InSection.AddMenuEntry("Texture_Texture2DArray", Label, ToolTip, Icon, UIAction);
					}
				}

				if (Context->SelectedAssets.Num() == 1 && ClassPathPermissionList->PassesFilter(UVolumeTexture::StaticClass()->GetClassPathName().ToString()))
                {
					const TAttribute<FText> Label = LOCTEXT("Texture2D_CreateVolumeTexture", "Create Volume Texture");
					const TAttribute<FText> ToolTip = LOCTEXT("Texture2D_CreateVolumeTextureToolTip", "Creates a new volume texture using this texture.");
					const FSlateIcon Icon = FSlateIcon(FAppStyle::GetAppStyleSetName(), "ContentBrowser.AssetActions.VolumeTexture");
					const FToolMenuExecuteAction UIAction = FToolMenuExecuteAction::CreateStatic(&ExecuteCreateVolumeTexture);

					InSection.AddMenuEntry("Texture2D_CreateVolumeTexture", Label, ToolTip, Icon, UIAction);
				}
			}));
		}));
	});
}

#undef LOCTEXT_NAMESPACE

#Loc: <Workspace>/Engine/Plugins/Editor/EngineAssetDefinitions/Source/Private/AssetDefinition_TextureCube.cpp:62

Scope (from outer to inner):

file
lambda-function
lambda-function

Source code excerpt:

				{
					// share the AllowTexture2DArrayCreation CVar to toggle this rather than make a separate one for cubes
					static const auto AllowTextureArrayAssetCreationVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.AllowTexture2DArrayCreation"));
					if (AllowTextureArrayAssetCreationVar->GetValueOnGameThread() != 0)
					{
						const TAttribute<FText> Label = LOCTEXT("Texture_TextureCubeArray", "Create Texture Cube Array");
						const TAttribute<FText> ToolTip = LOCTEXT("Texture_CreateTextureCubeArrayTooltip", "Creates a new texture cube array.");

						//static const FName NameTextureCube("ClassIcon.TextureCube"); // <- doesn't exist! (FIXME)
						static const FName NameTextureCube("ClassIcon.TextureRenderTargetCube"); // <- wrong (we are not a render target) but does exist
						const FSlateIcon Icon = FSlateIcon(FAppStyle::GetAppStyleSetName(), NameTextureCube);
						const FToolMenuExecuteAction UIAction = FToolMenuExecuteAction::CreateStatic(&ExecuteCreateTextureArray);

						InSection.AddMenuEntry("Texture_TextureCubeArray", Label, ToolTip, Icon, UIAction);
					}
				}
			}));
		}));
	});
}

#undef LOCTEXT_NAMESPACE

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Factories/Texture2DArrayFactory.cpp:29

Scope (from outer to inner):

file
function     bool UTexture2DArrayFactory::CanCreateNew

Source code excerpt:

bool UTexture2DArrayFactory::CanCreateNew() const
{
	static const auto AllowTextureArrayAssetCreationVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.AllowTexture2DArrayCreation"));
	return (AllowTextureArrayAssetCreationVar->GetValueOnGameThread() == 1);
}

UObject* UTexture2DArrayFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
{
	static const auto AllowTextureArrayAssetCreationVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.AllowTexture2DArrayCreation"));

	if (AllowTextureArrayAssetCreationVar->GetValueOnGameThread() == 0)
	{
		UE_LOG(LogTexture, Warning, TEXT("Texture2DArray creation failed. Enable by using console command r.AllowTexture2DArrayCreation\n"));
		return nullptr;
	}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Materials/MaterialExpressions.cpp:329

Scope (from outer to inner):

file
function     bool IsAllowedExpressionType

Source code excerpt:

	}

	static const auto AllowTextureArrayAssetCreationVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.AllowTexture2DArrayCreation"));

	// Exclude comments from the expression list, as well as the base parameter expression, as it should not be used directly
	const bool bSharedAllowed = Class != UMaterialExpressionComment::StaticClass() 
		&& Class != UMaterialExpressionPinBase::StaticClass()
		&& Class != UMaterialExpressionParameter::StaticClass()
		&& (Class != UMaterialExpressionTextureSampleParameter2DArray::StaticClass() || AllowTextureArrayAssetCreationVar->GetValueOnGameThread() != 0);