MaterialParents

MaterialParents

#Overview

name: MaterialParents

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

It is referenced in 7 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of MaterialParents is to manage and store a mapping between predefined glTF material identifiers and their corresponding parent material assets in Unreal Engine 5. This variable is primarily used in the context of the Interchange system, specifically for handling glTF material imports and customizations.

MaterialParents is mainly relied upon by the Interchange subsystem, particularly within the glTF pipeline module. It is used in both the Editor and Runtime components of the Interchange plugin.

The value of this variable is typically set through the UGLTFPipelineSettings class, which inherits from UDeveloperSettings. This allows the variable to be configured in the project settings.

MaterialParents interacts with other variables and functions within the glTF pipeline, such as ExpectedMaterialInstanceIdentifiers and GenerateExpectedParametersList(). It’s also used in conjunction with material instance creation and validation processes.

Developers must be aware of the following when using this variable:

  1. It’s part of the “PredefinedglTFMaterialLibrary” category in the project settings.
  2. The variable is hidden in certain UI customizations, suggesting it might not be intended for direct user manipulation in all contexts.
  3. It plays a crucial role in mapping imported glTF materials to existing Unreal Engine materials.

Best practices when using this variable include:

  1. Ensure that all expected material identifiers are properly mapped to valid parent materials.
  2. Regularly validate the MaterialParents map using the ValidateMaterialInstancesAndParameters() function to catch any misconfigurations.
  3. When extending the glTF import pipeline, consider how changes might affect the MaterialParents mapping and update accordingly.
  4. Be cautious when modifying this variable directly, as it’s central to the glTF material import process and could affect the entire pipeline if misconfigured.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Plugins/Interchange/Runtime/Config/BaseInterchange.ini:58, section: [/Script/InterchangePipelines.GLTFPipelineSettings]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Plugins/Interchange/Editor/Source/Pipelines/Private/InterchangeGLTFPipelineCustomizations.cpp:87

Scope (from outer to inner):

file
function     void FInterchangeGLTFPipelineSettingsCustomization::CustomizeDetails

Source code excerpt:

	}
	
	TSharedRef< IPropertyHandle > PairingsHandle = DetailBuilder.GetProperty(GET_MEMBER_NAME_CHECKED(UGLTFPipelineSettings, MaterialParents));
	if (!PairingsHandle->IsValidHandle())
	{
		return;
	}

	DetailBuilder.HideProperty(PairingsHandle);

#Loc: <Workspace>/Engine/Plugins/Interchange/Editor/Source/Pipelines/Private/InterchangeGLTFPipelineCustomizations.cpp:133

Scope (from outer to inner):

file
function     void FInterchangeGLTFPipelineSettingsCustomization::CustomizeDetails

Source code excerpt:

	IDetailCategoryBuilder& GLTFPredefinedMaterialLibraryCategory = DetailBuilder.EditCategory("PredefinedglTFMaterialLibrary", FText::FromString("Predefined glTF Material Library"));

	DetailBuilder.HideCategory(GET_MEMBER_NAME_CHECKED(UGLTFPipelineSettings, MaterialParents));
}

#Loc: <Workspace>/Engine/Plugins/Interchange/Runtime/Source/Pipelines/Private/InterchangeglTFPipeline.cpp:36

Scope (from outer to inner):

file
function     TArray<FString> UGLTFPipelineSettings::ValidateMaterialInstancesAndParameters

Source code excerpt:

	TArray<FString> ExpectedIdentifiers = ExpectedMaterialInstanceIdentifiers;
	TArray<FString> IdentifiersUsed;
	MaterialParents.GetKeys(IdentifiersUsed);
	for (const FString& Identifier : IdentifiersUsed)
	{
		ExpectedIdentifiers.Remove(Identifier);
	}
	for (const FString& ExpectedIdentifier : ExpectedIdentifiers)
	{

#Loc: <Workspace>/Engine/Plugins/Interchange/Runtime/Source/Pipelines/Private/InterchangeglTFPipeline.cpp:46

Scope (from outer to inner):

file
function     TArray<FString> UGLTFPipelineSettings::ValidateMaterialInstancesAndParameters

Source code excerpt:

	}

	for (const TPair<FString, FSoftObjectPath>& MaterialParent : MaterialParents)
	{
		TSet<FString> ExpectedParameters = GenerateExpectedParametersList(MaterialParent.Key);

		if (UMaterialInstance* ParentMaterialInstance = Cast<UMaterialInstance>(MaterialParent.Value.TryLoad()))
		{
			TArray<FGuid> ParameterIds;

#Loc: <Workspace>/Engine/Plugins/Interchange/Runtime/Source/Pipelines/Private/InterchangeglTFPipeline.cpp:208

Scope (from outer to inner):

file
function     void UGLTFPipelineSettings::BuildMaterialInstance

Source code excerpt:


	FString Parent;
	if (const FSoftObjectPath* ObjectPath = MaterialParents.Find(ParentIdentifier))
	{
		Parent = ObjectPath->GetAssetPathString();
	}
	else
	{
		UE_LOG(LogInterchangePipeline, Warning, TEXT("[Interchange] Failed to load MaterialParent for ParentIdentifier: %s"), *ParentIdentifier);

#Loc: <Workspace>/Engine/Plugins/Interchange/Runtime/Source/Pipelines/Public/InterchangeglTFPipeline.h:23

Scope (from outer to inner):

file
class        class UGLTFPipelineSettings : public UDeveloperSettings

Source code excerpt:

public:
	UPROPERTY(EditAnywhere, config, Category = "PredefinedglTFMaterialLibrary", meta = (DisplayName = "Predefined glTF Material Library"))
	TMap<FString, FSoftObjectPath> MaterialParents;

	TArray<FString> ValidateMaterialInstancesAndParameters() const;

	void BuildMaterialInstance(const UInterchangeShaderGraphNode* ShaderGraphNode, UInterchangeMaterialInstanceFactoryNode* materialInstanceNode);

	bool IsMaterialParentsEditible() { return bMaterialParentsEditible; }

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Materials/MaterialInstance.cpp:1200

Scope (from outer to inner):

file
function     void UMaterialInstance::LogMaterialsAndTextures

Source code excerpt:

		const UMaterialInterface* CurrentMaterialInterface = this;
		{
			TSet<const UMaterialInterface*> MaterialParents;

			// Walk up the parent chain to the materials to use.
			while (CurrentMaterialInterface && !MaterialParents.Contains(CurrentMaterialInterface))
			{
				MaterialParents.Add(CurrentMaterialInterface);

				const UMaterialInstance* CurrentMaterialInstance = Cast<const UMaterialInstance>(CurrentMaterialInterface);
				const UMaterial* CurrentMaterial = Cast<const UMaterial>(CurrentMaterialInterface);

				// The parent material is the first parent of this class.
				if (!MaterialToUse && CurrentMaterial)