r.PreventInvalidMaterialConnections
r.PreventInvalidMaterialConnections
#Overview
name: r.PreventInvalidMaterialConnections
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Controls whether users can make connections in the material editor if the system\ndetermines that they may cause compile errors\n0: Allow all connections\n1: Prevent invalid connections
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.PreventInvalidMaterialConnections is to control whether users can make potentially invalid connections in the material editor that may cause compile errors.
This setting variable is primarily used in the Unreal Engine’s material editing system, specifically within the UnrealEd module. It affects the behavior of the material graph schema when users attempt to create connections between nodes in the material editor.
The value of this variable is set through a console variable (CVar) named CVarPreventInvalidMaterialConnections. It is initialized with a default value of 1, which means invalid connections are prevented by default.
The associated variable CVarPreventInvalidMaterialConnections directly interacts with r.PreventInvalidMaterialConnections. They share the same value and purpose.
Developers must be aware that this variable affects the user experience in the material editor. When set to 1 (default), it prevents users from creating connections that the system determines may cause compile errors. When set to 0, it allows all connections, potentially leading to compilation issues.
Best practices when using this variable include:
- Keep it enabled (set to 1) during development to catch potential issues early.
- Consider temporarily disabling it (set to 0) if you need to create experimental or unconventional material setups that the system might incorrectly flag as invalid.
- Be cautious when disabling this feature, as it may lead to materials that fail to compile or behave unexpectedly.
Regarding the associated variable CVarPreventInvalidMaterialConnections:
Its purpose is identical to r.PreventInvalidMaterialConnections - it controls the prevention of invalid material connections in the editor.
This variable is used in both the UnrealEd module and the TextureGraphEditor plugin. It’s primarily accessed in the material graph schema classes to determine whether to allow or disallow certain pin connections.
The value of CVarPreventInvalidMaterialConnections is set when the console variable is initialized, and it can be changed at runtime through console commands.
Developers should be aware that this variable is accessed using the GetValueOnGameThread() method, which means its value can potentially change during runtime.
Best practices for using CVarPreventInvalidMaterialConnections include:
- Use it consistently across different graph schemas that deal with material-like connections.
- Consider the performance implications of frequently checking this value, especially in performance-critical code paths.
- If you’re extending the material system or creating custom node graphs, consider adhering to this setting for consistency with the main material editor behavior.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/MaterialGraphSchema.cpp:546
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarPreventInvalidMaterialConnections(
TEXT("r.PreventInvalidMaterialConnections"),
1,
TEXT("Controls whether users can make connections in the material editor if the system\n")
TEXT("determines that they may cause compile errors\n")
TEXT("0: Allow all connections\n")
TEXT("1: Prevent invalid connections"),
ECVF_Cheat);
#Associated Variable and Callsites
This variable is associated with another variable named CVarPreventInvalidMaterialConnections
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Plugins/Experimental/TextureGraph/Source/TextureGraphEditor/Private/EdGraph/TG_EdGraphSchema.cpp:172
Scope (from outer to inner):
file
function const FPinConnectionResponse UTG_EdGraphSchema::CanCreateConnection
Source code excerpt:
const FPinConnectionResponse UTG_EdGraphSchema::CanCreateConnection(const UEdGraphPin* A, const UEdGraphPin* B) const
{
// bool bPreventInvalidConnections = CVarPreventInvalidMaterialConnections.GetValueOnGameThread() != 0;
// Make sure the pins are not on the same node
if (A->GetOwningNode() == B->GetOwningNode())
{
return FPinConnectionResponse(CONNECT_RESPONSE_DISALLOW, LOCTEXT("ConnectionSameNode", "Both are on the same node"));
}
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/MaterialGraphSchema.cpp:545
Scope: file
Source code excerpt:
}
static TAutoConsoleVariable<int32> CVarPreventInvalidMaterialConnections(
TEXT("r.PreventInvalidMaterialConnections"),
1,
TEXT("Controls whether users can make connections in the material editor if the system\n")
TEXT("determines that they may cause compile errors\n")
TEXT("0: Allow all connections\n")
TEXT("1: Prevent invalid connections"),
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/MaterialGraphSchema.cpp:556
Scope (from outer to inner):
file
function const FPinConnectionResponse UMaterialGraphSchema::CanCreateConnection
Source code excerpt:
const FPinConnectionResponse UMaterialGraphSchema::CanCreateConnection(const UEdGraphPin* A, const UEdGraphPin* B) const
{
bool bPreventInvalidConnections = CVarPreventInvalidMaterialConnections.GetValueOnGameThread() != 0;
// Make sure the pins are not on the same node
if (A->GetOwningNode() == B->GetOwningNode())
{
return FPinConnectionResponse(CONNECT_RESPONSE_DISALLOW, LOCTEXT("ConnectionSameNode", "Both are on the same node"));
}