# C++ UMaterialInstanceDynamic output function?

**URL:** <https://forums.unrealengine.com/t/c-umaterialinstancedynamic-output-function/451754>\
**Category:** Rendering\
**Tags:** tarray:-arrays-in-un, unreal-engine, CPP, question\
**Created:** [July 5, 2019, 3:47pm UTC](https://forums.unrealengine.com/t/c-umaterialinstancedynamic-output-function/451754 "2019-07-05T15:47:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![R0tn3k](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@R0tn3k](https://forums.unrealengine.com/u/R0tn3k)\
**Post date:** [July 5, 2019, 3:47pm UTC](https://forums.unrealengine.com/t/c-umaterialinstancedynamic-output-function/451754/1 "2019-07-05T15:47:34Z")

</div>

Hi, I want to have a MaterialInstance-TArray in my Gamemode together with a “GetMaterialArray()” function for other to use those materials.  
In the MyGameMode.h I have:

```
TArray<UMaterialInstanceDynamic> MaterialListArray;
void MaterialList(TArray<UMaterialInstanceDynamic>& Materials);

```

and in the cpp I tried:

```
void MyGameMode::MaterialList(TArray<UMaterial>& Materials) 
{
	Materials.Empty();
	Materials.Append(MaterialListArray);
}

```

But I get the error message that it’s not allowed to get access to private members of UMaterial  
I also tried Materials.Append(MaterialListArray.GetData()); but that isn’t working either. Unfortunately Google didn’t really help, so I’m trying my luck here - thanks for the help

---

<div class="post-metadata">

**Author:** ![Ghar](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ghar](https://forums.unrealengine.com/u/Ghar)\
**Post date:** [July 5, 2019, 8:45pm UTC](https://forums.unrealengine.com/t/c-umaterialinstancedynamic-output-function/451754/2 "2019-07-05T20:45:51Z")

</div>

Hello. I think you forgot the \*

Try this:

.h:

```
TArray<UMaterialInstanceDynamic*> MaterialListArray;
void MaterialList(TArray<UMaterialInstanceDynamic*>& Materials);

```

.cpp:

```
void MyGameMode::MaterialList(TArray<UMaterialInstanceDynamic*>& Materials)
{
	Materials = MaterialListArray;
}
```

---

<div class="post-metadata">

**Author:** ![R0tn3k](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@R0tn3k](https://forums.unrealengine.com/u/R0tn3k)\
**Post date:** [July 7, 2019, 3:46pm UTC](https://forums.unrealengine.com/t/c-umaterialinstancedynamic-output-function/451754/3 "2019-07-07T15:46:28Z")

</div>

Found it out later the same day, you are absolutely right, thanks still for taking the time for the next one having that problem 😃
