# Creating a dynamic material instance on C++?

**URL:** <https://forums.unrealengine.com/t/creating-a-dynamic-material-instance-on-c/362062>\
**Category:** Asset Creation\
**Tags:** unreal-engine, question\
**Created:** [June 26, 2016, 2:38pm UTC](https://forums.unrealengine.com/t/creating-a-dynamic-material-instance-on-c/362062 "2016-06-26T14:38:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mago314](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mago314](https://forums.unrealengine.com/u/mago314)\
**Post date:** [June 26, 2016, 2:38pm UTC](https://forums.unrealengine.com/t/creating-a-dynamic-material-instance-on-c/362062/1 "2016-06-26T14:38:17Z")

</div>

Hello there!

I have an actor with several meshes. I would like to create a dynamic material and then apply it to the components. However, I can’t seem to find how to do this.

Where should the material be instantiated? And, should it be applied on the Constructor? How can the parameters be changed?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![UPO33](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UPO33](https://forums.unrealengine.com/u/UPO33)\
**Post date:** [June 26, 2016, 3:02pm UTC](https://forums.unrealengine.com/t/creating-a-dynamic-material-instance-on-c/362062/2 "2016-06-26T15:02:24Z")

</div>

O\_o

```
	UPROPERTY(EditAnywhere)
	UMaterialInterface* Material;

	virtual void BeginPlay() override
	{
		//create dynamic material anywhere u like, Constructor or anywhere .
		UMaterialInstanceDynamic* DynMaterial = UMaterialInstanceDynamic::Create(Material, this);
		//set paramater with Set***ParamaterValue
		DynMaterial->SetScalarParameterValue("MyParameter", myFloatValue);
		MyComponent1->SetMaterial(0, DynMaterial);
		MyComponent2->SetMaterial(0, DynMaterial);
		//...
	}
```

---

<div class="post-metadata">

**Author:** ![Sir\_Edlin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sir_edlin/32/474304_2.png) [@Sir\_Edlin](https://forums.unrealengine.com/u/Sir_Edlin)\
**Post date:** [July 17, 2017, 7:54am UTC](https://forums.unrealengine.com/t/creating-a-dynamic-material-instance-on-c/362062/3 "2017-07-17T07:54:50Z")

</div>

Hi, can you please show an example how would one store created material to disk?

Tank you

---

<div class="post-metadata">

**Author:** ![MichaelWion](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MichaelWion](https://forums.unrealengine.com/u/MichaelWion)\
**Post date:** [February 12, 2018, 10:15am UTC](https://forums.unrealengine.com/t/creating-a-dynamic-material-instance-on-c/362062/4 "2018-02-12T10:15:58Z")

</div>

The actual material? That’s not directly supported by the engine, but you can dig around engine source to see how they do it (probably something involving the Asset Manager).  
You could also just save a texture to disk, but either way it’s not relevant to this thread.  
You’re better off just starting your own thread with that question.

---

<div class="post-metadata">

**Author:** ![Fernando.Cesi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fernando.Cesi](https://forums.unrealengine.com/u/Fernando.Cesi)\
**Post date:** [November 1, 2018, 1:33pm UTC](https://forums.unrealengine.com/t/creating-a-dynamic-material-instance-on-c/362062/5 "2018-11-01T13:33:21Z")

</div>

If the materials are created could it be possible to loaded them using StaticLoadObject() … I’m guessing not but wanted more insight on instanced materials in C++ can you onle create them? not load already created Mat instance uasset?

---

<div class="post-metadata">

**Author:** ![Precutsplash451](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Precutsplash451](https://forums.unrealengine.com/u/Precutsplash451)\
**Post date:** [June 13, 2021, 3:35pm UTC](https://forums.unrealengine.com/t/creating-a-dynamic-material-instance-on-c/362062/6 "2021-06-13T15:35:57Z")

</div>

You could just store the parameters that you changed/used instead of the entire material
