# Using Arrays in Materials

**URL:** <https://forums.unrealengine.com/t/using-arrays-in-materials/383031>\
**Category:** Rendering\
**Tags:** unreal-engine, Array, loop, hlsl, question\
**Created:** [January 26, 2017, 4:20pm UTC](https://forums.unrealengine.com/t/using-arrays-in-materials/383031 "2017-01-26T16:20:19Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![anonymous\_user\_4b3639a6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4b3639a6](https://forums.unrealengine.com/u/anonymous_user_4b3639a6)\
**Post date:** [March 28, 2017, 11:09am UTC](https://forums.unrealengine.com/t/using-arrays-in-materials/383031/5 "2017-03-28T11:09:26Z")

</div>

Unfortunately I didnt find a way to send custom structs to the shader.  
I used MaterialParameterCollection to send specific data via code to my Material.

To do this:

1. Create a MaterialParameterCollection Asset in the Unreal Editor

2. Add a specific number of elements to the Array (like 10, 20, 128, 256…)

3. Get this Asset in code by using ConstructorHelpers:  
static ConstructorHelpers::FObjectFinder MaterialParamCollection(TEXT(“MaterialParameterCollection’/Game/Materials/EchoCollection.EchoCollection’”));

4. Next is to fill the MaterialParameterCollection:

To actually iterate through this array you have to write custom expression code in your materials

!!!Warning!!! You have to use one Vector or Scalar Parameter from the Collection as an Input. Otherwise the shader doesnt know your collection

 ![131907-screenshot+2017-03-28+13.00.35.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/9/9/699944c87c1f677aa219c7db408629a5d822988d.png)

```
for(int i = 0; i < NumberOfParams; ++i)
{
    float4 VectorParam = MaterialCollection0.Vectors[i];
    //Do something...
}

```

This should be it 🙂

---

_[View the full topic](https://forums.unrealengine.com/t/using-arrays-in-materials/383031)._
