Function stops working correctly after return node is added?

Hey Devs,

I have a function that finds all static mesh actors with a specific tag, creates a material instance, and sets that instance as the material for the components with that tag. I’m working with datasmith and vray, so this is the easiest way to set it up with how my environments are importing.

Instead of linking the “as primitive component” output to the “Set Material” directly, though, I want to stop after creating the material instance, and I want to link the new material instance’s return value to an output on the return node in my function. Then, outside of the function in the regular graph, I’ll set that material instance as a variable, and use that new variable to “set material”.

I need to create separate material instance variables for each ‘part’ of the ring, and they’re all based on the same base material, which is why I want to just use this one function to create a new material instance for each different part of the ring. That way at runtime, the user can choose their options for each part of the ring, which will change the material parameters for that part only.

The function works as intended, until I add the return node. Both with and without outputs, instead of applying the material instance to every primitive component, it only chooses one.

Why is that happening and how can i fix it?

Thank you!!

alt text

It is because you are Returning out of the function during the loop. Put the Return node on the loop’s Completed pin instead so that it doesnt exit the function and Return until the loop has finished.