Setting Dynamic Material Instance for Skeletal/Static meshes using C++?

I suggest you leave it as is was, comment every line, and start testing one by one compiling until you get to the crash.

This is working for me:

void ADynamicMatTest::SetDynamicMat()
{
	static ConstructorHelpers::FObjectFinder<UMaterialInterface>Material(
		TEXT("/Game/Blueprints/Misc/M_ToCreateInstance.M_ToCreateInstance")
	);
	UMaterialInstanceDynamic* DynamicMaterial = UMaterialInstanceDynamic::Create(
		Material.Object, 
		this,
		FName("M_CreatedInstance")
	);

	if (Material.Succeeded())
	{
		StaticMesh->SetMaterial(0, DynamicMaterial);
	}
}

Your problem could easily be a bad path to the material.

2 Likes