Hi, in my blueprint function library, I have a recursive function that adds values to a local map variable and then returns this map variable. All good inside the function, I can see the values on the return node.
But when I call this function inside another function, it doesn’t return anything, the map variable is empty.
I even added a text variable on the return node to see if that gets passed, and nothing. It sometimes even crashes the engine.
What gives?
What is shown is poorly scripted and seems unsafe
- cache the data, avoid accessing data pins from other exec branches. While it should technically work here since it’s a Break loop, I would not rely on this - it is asking for trouble and I’d expect it to eventually crash:
Found what you needed? cache it, break, complete, use cache. Done with the cache? Push it back into the container.
- no return will return defaults. Intended? That’s the recursion, right? Also, why not take a screenshot that has more than just a handful of pixels…
- the loop at the bottom doesn’t do anything
- tMaps can be passed by ref; here, you’re passing a copy. This may be irrelevant for the very described issue, but may as well be a neat solution. Not enough info to tell more, though.
Because of low quality picture , what are you removing?
I took it node by node. Apprently, calling the function within itself, the way I did it, breaks it. So I made a new simple function:
And the result is also 0. So what am I doing wrong here?
Also, I don’t know what you mean by “cache it”. How do I do that? And why is it “unsafe scripting”? What can I do better?
what is the initial value of new param?
If it is 0 then the last one should return 4, but this will not return because you are not returning it (from the true branch).
Yep, that was it. I didn’t think I’d need a return node there as well, since I have one when the function ends. Which leaves me a bit confused, but it works.
Thanks a lot.
Thanks. What do you mean by that?
Have a look at the 4 bullet points.