# How to initialize an array of structures with a given size using Init

**URL:** <https://forums.unrealengine.com/t/how-to-initialize-an-array-of-structures-with-a-given-size-using-init/554812>\
**Category:** C++\
**Tags:** Structure, unreal-engine, UE4-27, question, CPP\
**Created:** [May 11, 2022, 5:09pm UTC](https://forums.unrealengine.com/t/how-to-initialize-an-array-of-structures-with-a-given-size-using-init/554812 "2022-05-11T17:09:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![teknosanity](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@teknosanity](https://forums.unrealengine.com/u/teknosanity)\
**Post date:** [May 11, 2022, 5:09pm UTC](https://forums.unrealengine.com/t/how-to-initialize-an-array-of-structures-with-a-given-size-using-init/554812/1 "2022-05-11T17:09:34Z")

</div>

I’m trying to initialize and fill an array of structures to a given N size with empty structures to be used. Init would not accept both NULL and ‘{}’ for the element to fill it with.

![Screenshot 2022-05-11 180314](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/5/e/d5e36e6f7c67fb490a780c46108c76287705af27.png)

![Screenshot 2022-05-11 180248](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/c/c/fcc969ff1463603747d7eb57304812a0d8434945.png)

---

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [May 11, 2022, 5:46pm UTC](https://forums.unrealengine.com/t/how-to-initialize-an-array-of-structures-with-a-given-size-using-init/554812/2 "2022-05-11T17:46:48Z")

</div>

When initializing an array, you need to indicate the values with which the elements will be initialized. In your case you have an array of structs, where struct element is also an array. So you need to indicate that in your Init():

```auto
TArray<FMaterialsArray> Tmp;
TArray<UMaterialInstance*> emptyMats;
Tmp.Init({emptyMats}, 10);

```

---

<div class="post-metadata">

**Author:** ![teknosanity](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@teknosanity](https://forums.unrealengine.com/u/teknosanity)\
**Post date:** [May 12, 2022, 1:54pm UTC](https://forums.unrealengine.com/t/how-to-initialize-an-array-of-structures-with-a-given-size-using-init/554812/3 "2022-05-12T13:54:44Z")

</div>

Thank you so much!

---

<div class="post-metadata">

**Author:** ![ClMcGee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ClMcGee](https://forums.unrealengine.com/u/ClMcGee)\
**Post date:** [November 29, 2023, 5:32pm UTC](https://forums.unrealengine.com/t/how-to-initialize-an-array-of-structures-with-a-given-size-using-init/554812/4 "2023-11-29T17:32:45Z")

</div>

@Tuerer Huge thanks! Helped me avoiding limbo with array out of bounds 0 of 0 😃
