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

**URL:** <https://forums.unrealengine.com/t/setting-dynamic-material-instance-for-skeletal-static-meshes-using-c/552079>\
**Category:** C++\
**Tags:** UE4-20, unreal-engine, UE4, question, CPP\
**Created:** [May 8, 2022, 4:34pm UTC](https://forums.unrealengine.com/t/setting-dynamic-material-instance-for-skeletal-static-meshes-using-c/552079 "2022-05-08T16:34:16Z")\
**Posts on this page:** 1\
**Showing post:** 26

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [May 8, 2022, 9:38pm UTC](https://forums.unrealengine.com/t/setting-dynamic-material-instance-for-skeletal-static-meshes-using-c/552079/26 "2022-05-08T21:38:51Z")

</div>

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:

```auto
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.

---

_[View the full topic](https://forums.unrealengine.com/t/setting-dynamic-material-instance-for-skeletal-static-meshes-using-c/552079)._
