# \[bug\] Get Materials from mesh returning an empty array

**URL:** <https://forums.unrealengine.com/t/bug-get-materials-from-mesh-returning-an-empty-array/304006>\
**Category:** Rendering\
**Tags:** unreal-engine, bug-report, Blueprint, question\
**Created:** [January 15, 2015, 2:49am UTC](https://forums.unrealengine.com/t/bug-get-materials-from-mesh-returning-an-empty-array/304006 "2015-01-15T02:49:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_20bc299e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_20bc299e](https://forums.unrealengine.com/u/anonymous_user_20bc299e)\
**Post date:** [January 15, 2015, 2:49am UTC](https://forums.unrealengine.com/t/bug-get-materials-from-mesh-returning-an-empty-array/304006/1 "2015-01-15T02:49:13Z")

</div>

Calling Get Materials from a character always return an empty array. I tested it in the “Animation” Level of content examples in 4.6.1 to be sure on playable Owen character to be sure.

It appears calling “Set Material” will fill Get Materials array with new material at specified index, and rest of array with nulls. For example, if I call “Set Material” with index 5 and a new material, then call “Get Materials”, array returned is 5 nulls (indices 0-4) then new Material (index 5). For some reason, this breaks “Get Num Materials” which now starts to return 6.

I suspect bug is due to the “Materials” array in Mesh attempting to be populated before materials have loaded in. This doesn’t explain why “Get Num Materials” works initially though.

 ![26689-bug.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/8/6/386a83cd13599308feea5706b1b029085e8f520c.jpeg)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_20bc299e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_20bc299e](https://forums.unrealengine.com/u/anonymous_user_20bc299e)\
**Post date:** [January 15, 2015, 3:05am UTC](https://forums.unrealengine.com/t/bug-get-materials-from-mesh-returning-an-empty-array/304006/2 "2015-01-15T03:05:23Z")

</div>

Here’s what Set Material does to that array:

 ![26690-bug2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/a/e/4aebfcf750000718220e2cbc79745c25cd1ebc4c.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_20bc299e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_20bc299e](https://forums.unrealengine.com/u/anonymous_user_20bc299e)\
**Post date:** [January 15, 2015, 10:42am UTC](https://forums.unrealengine.com/t/bug-get-materials-from-mesh-returning-an-empty-array/304006/3 "2015-01-15T10:42:39Z")

</div>

Get Materials is fixed in 4.7 beta revision 3. However, Set Material is still clearing all other materials before it adds new material. Here’s a workaround function you can make to get Set Material working properly.

 ![26754-bugworkaround.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/d/f/9df094769c4286faeade47366c6f74f163c582ed.png)

ED: top right “Element Index” pin should be connected to Element Index on left. Must have ctrl-z-ed before screenshotting.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_33800a51](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_33800a51](https://forums.unrealengine.com/u/anonymous_user_33800a51)\
**Post date:** [January 15, 2015, 8:57pm UTC](https://forums.unrealengine.com/t/bug-get-materials-from-mesh-returning-an-empty-array/304006/4 "2015-01-15T20:57:31Z")

</div>

Hi Ohriginal,

As you’ve noted, issue you first reported was fixed in 4.7 with new GetMaterials node, which returns correct number of materials used. I believe you’re using Set Material node incorrectly, however. node is designed to set a material on an existing material slot, not create a new one. You’re updating an array that doesn’t have any actual impact on number of materials on mesh (thus GetNumMaterials will not update when you add to array with this method).

I have entered a bug report for this behavior (UE-7635), because I believe Set Material function should not be able to add to array. I also recommended a warning if this is done. I will let you know what developers say when I see an update. Thanks for report!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_20bc299e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_20bc299e](https://forums.unrealengine.com/u/anonymous_user_20bc299e)\
**Post date:** [January 16, 2015, 12:23am UTC](https://forums.unrealengine.com/t/bug-get-materials-from-mesh-returning-an-empty-array/304006/5 "2015-01-16T00:23:20Z")

</div>

Hmm, I believe we are one same page but I just want to be sure.

> node is designed to set a material on an existing material slot, not create a new one.  
> That is my intention as well. However I am seeing below pic as a result.

 ![26798-clarification.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/5/b/b5ba79f16c60d4736310bd4fccc5837d1b33bafa.png)

Note that Set Material is actually setting correct material in correct slot (based on what I see on character), it’s just permanently messing up new GetMaterials node.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_33800a51](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_33800a51](https://forums.unrealengine.com/u/anonymous_user_33800a51)\
**Post date:** [January 16, 2015, 6:33pm UTC](https://forums.unrealengine.com/t/bug-get-materials-from-mesh-returning-an-empty-array/304006/6 "2015-01-16T18:33:31Z")

</div>

Ah, interesting. Okay, I have updated bug to include these notes. Thanks!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_33800a51](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_33800a51](https://forums.unrealengine.com/u/anonymous_user_33800a51)\
**Post date:** [March 31, 2015, 8:28pm UTC](https://forums.unrealengine.com/t/bug-get-materials-from-mesh-returning-an-empty-array/304006/7 "2015-03-31T20:28:19Z")

</div>

Hi Ohriginal,

I just verified that this has been fixed in our main internal branch, and fix should be included in a future release, probably 4.8.
