[bug] Get Materials from mesh returning an empty array

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.

Here’s what Set Material does to that array:

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.

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

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!

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.

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.

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

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.