# I can not add a material from c ++

**URL:** <https://forums.unrealengine.com/t/i-can-not-add-a-material-from-c/433693>\
**Category:** Rendering\
**Tags:** unreal-engine, instances, staticmesh, question, CPP\
**Created:** [September 13, 2018, 3:52am UTC](https://forums.unrealengine.com/t/i-can-not-add-a-material-from-c/433693 "2018-09-13T03:52:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielf94](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@danielf94](https://forums.unrealengine.com/u/danielf94)\
**Post date:** [September 13, 2018, 3:52am UTC](https://forums.unrealengine.com/t/i-can-not-add-a-material-from-c/433693/1 "2018-09-13T03:52:11Z")

</div>

Hello!

I can not add a material from c ++

my code..

 ![253546-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/0/f/10f6ad611b144f3323e9329e82e6b3a63d984ee4.png)

 ![253547-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/4/8/148c02a264588e32900fe35395cf4af9441b8aa3.png)

 ![253548-captura-de-pantalla-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/7/5/175eb78b38c00139c389e18ed3f124a8cfb434e0.png)

\*\*

## the static mesh if it is loaded but the material does not

\*\*

 ![253550-captura.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/f/3/ef35e14b65fbd6ef607d33b575e7769829598dd6.png)

\*\*

## result:

\*\*

 ![253561-captura2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/2/d/62d4913ae925eb155440af055d876288a981f659.png)

\*\*

## the material does not load, what am I doing wrong

\*\*

---

<div class="post-metadata">

**Author:** ![erikdubbelboer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@erikdubbelboer](https://forums.unrealengine.com/u/erikdubbelboer)\
**Post date:** [September 13, 2018, 5:01am UTC](https://forums.unrealengine.com/t/i-can-not-add-a-material-from-c/433693/2 "2018-09-13T05:01:06Z")

</div>

It’s not a Material Instance, it’s a Material. So try changing `UMaterialInstance` to `UMaterial`.

---

<div class="post-metadata">

**Author:** ![danielf94](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@danielf94](https://forums.unrealengine.com/u/danielf94)\
**Post date:** [September 13, 2018, 6:15am UTC](https://forums.unrealengine.com/t/i-can-not-add-a-material-from-c/433693/3 "2018-09-13T06:15:07Z")

</div>

@erikdubbelboer ok friend…

now if you add it in the editor, but when compiling the materials are not reflected

 ![253571-siiiiiiiiiiiiiiiiii.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/e/7/ae78bdceae890530c56af1e0c5d91a058ed13b99.png)

try creating an instance of the material like this:

 ![253568-captura-de-pantalla-4.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/4/9/b495d4a5d6da6b6ade1a6be09bfb0b03ee7cd2f9.png)

and changing my code like this:

 ![253569-nueviooooooo.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/c/e/1cee1546347f3e4c10642acca13cd6967ab907f4.png)

it does not work, materials are not reflected

![253570-mate.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/8/4/b8429c559ba9044811b2c3690c78be9af19fb60d.png)

Now I realized that if I change the component from “UInstancedStaticMeshComponent” to “UStaticMeshComponent” if it works, but I need them to be instances. “UInstancedStaticMeshComponent”

---

<div class="post-metadata">

**Author:** ![erikdubbelboer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@erikdubbelboer](https://forums.unrealengine.com/u/erikdubbelboer)\
**Post date:** [September 13, 2018, 11:59am UTC](https://forums.unrealengine.com/t/i-can-not-add-a-material-from-c/433693/4 "2018-09-13T11:59:21Z")

</div>

Materials have an attribute “Used With InstancedStaticMeshes”  
You have to toggle that to true in the editor and then it should work.

---

<div class="post-metadata">

**Author:** ![danielf94](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@danielf94](https://forums.unrealengine.com/u/danielf94)\
**Post date:** [September 13, 2018, 5:37pm UTC](https://forums.unrealengine.com/t/i-can-not-add-a-material-from-c/433693/5 "2018-09-13T17:37:13Z")

</div>

@erikdubbelboer thank you very much, that was all
