UE554: PrimitiveOptions.MaterialID has strange behavior (And Completely Broken on Revolve)(Geometry Script)

Cannot select an ID with a zero value

PrimitiveOptions.MaterialID = 0;

If you do this, the last material in the array will be selected.

Except for the dynamic mesh returned by the function.

void AMyClass::RebuildGeneratedMesh(UDynamicMesh* TargetMesh)
{
}

For this mesh " TargetMesh", MaterialID = 0 seems to work correctly.

Any other MaterialID different to zero works correctly.

Except for the REVOLVE primitive. In this case no MaterialID value works correctly.
The Revolve always has the last element of the material array.

I found this in the code for primitive functions.

It seems that (MaterialID = 0) is a special case for some reason I don’t know.

But this makes the zero element of the materials array completely useless.


I had to leave it empty so I could use the rest of the materials with some logic.

Below is a video to show the problem

As you can see it works correctly as long as MaterialID is different from zero.
The revolve (The curved area) always malfunctions


I hope someone reports success to the development team.
My previous experiences doing it led me to make the decision to never do it again…
That’s why I just edit a post. My work is done!!


I fixed the Revolve problem using this function instead of PrimitiveOptions.MaterialID

UDynamicMesh* SetMaterilaId(UDynamicMesh* TargetMesh, const int MaterialID)
{
	FGeometryScriptIndexList TriangleIDList;

	bool bHasTriangleIDGaps = false;
	UGeometryScriptLibrary_MeshQueryFunctions::GetAllTriangleIDs
	(
		TargetMesh, 
		TriangleIDList, 
		bHasTriangleIDGaps
	);	

	bool bDeferChangeNotifications = false; 
	UGeometryScriptDebug* Debug = nullptr;
	
	return UGeometryScriptLibrary_MeshMaterialFunctions::SetMaterialIDOnTriangles
	(
		TargetMesh, 
		TriangleIDList, 
		MaterialID, 
		bDeferChangeNotifications, 
		Debug
	);
}

NOTE: Use this function before RemapMaterialIDs(…);


I also managed to remove the useless material slot zero, just use this function

void FMaterials::Apply(UDynamicMesh* TargetMesh, const TObjectPtr<UDynamicMeshComponent> &DynamicMeshComponent) const
{
	if (MaterialsList.Num()==0) return;
	
	if (!IsValid(DynamicMeshComponent)) return;
	

	TArray<UMaterialInterface*> CompactedMaterialList = MaterialsList;
	CompactedMaterialList.RemoveAt(0);

	UGeometryScriptDebug* Debug = nullptr;	


	int MissingMaterialID = -1;
	TargetMesh = UGeometryScriptLibrary_MeshMaterialFunctions::RemapToNewMaterialIDsByMaterial
	(
		TargetMesh, 
		MaterialsList, 
		CompactedMaterialList, 
		MissingMaterialID, 
		Debug
	);
	
	DynamicMeshComponent->ConfigureMaterialSet(CompactedMaterialList,true);
}

if someone know why the (MaterialID = 0) is not working let me know please.


A wonderfull bug Epic team… two bugs for the price of one… i had a very funny day today… probably i will enjoy it the rest of the week.


I hope this help somone else.
Best Regards!!

1 Like