BP function return array is always empty

I have a recursive function that sorts every player and enemy by speed (from lowest to highest) and returns the result in an actor array.
Inside the function, when it is about to return, the array is correctly populated, but when I check the resulting array that is set after executing the function, it is always empty. It seems as if the return array isn’t passed to the function.

If I print the length of the array inside the function and the length of the one returned by the function, I get something like this :

I have even tried to plug in a “make array” to the return node directly, and the function still returns an empty array :

I have no idea what to do here, because I really need a recursive function for this to work.

im surprised you dont have any looping errors. it looks like your trying to call a function from inside itself, ive never tried that but it seems wrong.

It works fine, up until the point I actually return the array, where it is always empty. But if I print the contents of the array just before returning it, the function has done its job correctly.
Are recursive functions that uncommon in Blueprints ? They’re very common in traditionnal programming languages.

I used a recursive blueprint function to build a random maze for my game.

Is that ListBuffer var a local variable or a class variable?

Looks scary at a glance.

ListBuffer is a local variable, yes.

Should I pass a direct reference of the variable I want to change instead ? (I forgot what it’s called in Blueprints)

You’re not returning the result of the recursive call. Attach the result of the recursive call to a return pin and you should be okay.

I don’t really understand. You mean I have to do this ? Doesn’t make much sense to me.

That doesn’t work. The array is empty both inside the function and when I return it.

I also tried this :

Doesn’t work either.

I set the result of the previous function in a local variable directly when starting the new one, so it should be working when I return that value to the main blueprint.

Here’s what I do “outside” that function :

It’s pretty straightforward.

I finally solved my problem by making a non-recursive version of my function, and it’s better in every aspect : size, readability, speed, and memory usage (not that memory is an issue, but still).

  1. What do you do “outside” of this function? How are you using the output array?
  2. If “list buffer” is a local variable are you using it as the output to set a “class variable” somewhere outside of the function? (as I mention in point #1)
  3. Also your “test” with the “make array” thing would be empty…you haven’t hooked anything into the array pins