Add a Static Mesh component. Do not assign a mesh asset to it.
In the constructor, add the following nodes:
Add a reference to the Static Mesh component.
Add a Get Material Slot Names node, with the above SM reference as input
Add a ForEach node with the output of the Get Material Slot Names node as input.
Connect the Exec node from Construction Script to the ForEach.
Compile.
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.
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.
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.
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.