4.16.2 - Get Material Slot Names crash on undefined SM

Repro steps:

  1. Create a new Actor Blueprint.
  2. Add a Static Mesh component. Do not assign a mesh asset to it.
  3. In the constructor, add the following nodes:
  4. Add a reference to the Static Mesh component.
  5. Add a Get Material Slot Names node, with the above SM reference as input
  6. Add a ForEach node with the output of the Get Material Slot Names node as input.
  7. Connect the Exec node from Construction Script to the ForEach.
  8. Compile.
  9. Crash.

If you assign a mesh asset to the SM component, it works fine. Presumably, the Get Material Slot Names is returning null, and the ForEach node doesn’t have any handling for that.

Assigning a placeholder SM asset to the SM component prevents the crash. Would be nice if the node failed silently, allowing for these nodes to easily be used in abstract classes where the mesh isn’t assigned until instantiated.

Hello Meowstopher,

After doing some digging I was able to find that this is a known issue. I have provided a link to the public tracker. Please feel free to use the link provided for future updates.

Link: Removed

Make it a great day

Edit: Removed incorrect link

After taking a second look at the issue linked above, it appears you were correct. I have written up a separate report. I have provided a link below. Please feel free to use the link provided for future updates.

Link: Unreal Engine Issues and Bug Tracker (UE-47667)

Make it a great day

The foreach node can deal with 0 Objects fine. Problem is you try Pull out Slot Names from something that does not exist. Thats why you get a Crash. Use it like that to make sure there is a Mesh assigned from where you can pull Materials. https://i.imgur.com/uI5gTzT.png

And at Epic Staff its a good Idea to have a check here (not gonna submit a Pull request for that easy fix ;P)

Hi Rudy. Im affraid the issue reffers to something else (and is already fixed for 4.16 what we both tested on). See my Answer bellow.

Basicly we can ask the Mesh Component to get Material slot Names but it crashes because the Function itself does not check if there is a Mesh we could get the Material Names from. Its a tiny little fix to check if there is a Mesh first and it will return a empty Array of names as expected.