Why won't the For Each Loop work inside my Function Library

So, I’ve been having a problem using built-in macros (e.g. For-Each loops, Compare Int, etc.) in function libraries. When I was running 4.5, this (some selection sort code):

wouldn’t compile because of the For-Each loop, the For loop, and the CompareInt functions*. I have since updated to 4.7, and now the only problem is in the For-Each. The error it gives me is this:

When I have it jump to the error node, this is what comes up:

Every part of the macro involving arrays (including the “inputs” section) gives the same error. What’s the problem and how do I fix it?

*Interestingly enough, even when I was running 4.5, I had another function library in which I used the CompareInt function, and it worked fine in that one. I have no idea why it would work in one but not another.

Also, as a side note, does anyone know if they have added support for using time based events in function blueprints yet or if it’s still confined to the level blueprint? Because that’d be useful.

edit: The variable I’m connecting to the For-Each loop is a structure. That shouldn’t matter, though, should it?

I have this issue too. Been scratching my head why it’s not working properly, on a whim dragged all the logic out of the function and my code works perfectly. This has cost me hours!

Hey Thank you Lukewade2!

I found this question when I search for my problem, I have a variable in struct, and I can see it exist when I look directly to the blueprint when I press f8, but my function cannot find that variable for each loop! Thank to you if I drag them all from the function and paste in event graph it works!

They dont work because functions fire off as a single executed node, so certain functionality where it would need to do multiple executions just don’t work, its why delays aren’t supported in a function if Im remembering correctly. It will fire off the first loop body execution but not cycle through the rest. Maybe if you made a custom for each loop that will manually fire off the next index and you just loop the execution through it might work?