The first problem is the BlueprintCallable functions need to have a category specified. Easy enough.
After that you should consider having passing the array by reference (making it an ‘out’ parameter)
Finally (and this is something I didn’t realise till I just tried it), a TArray of uint32 doesn’t seem to be supported in blueprints. I have no idea why, but making it a TArray of int32 seems to work fine.
Thanks, it’s compiling now but still I can’t find the function in blueprint even with BlueprintCallable with Category. My earlier function with int32 instead of uint32 is compiling as well, but can’t be seen in blueprints too.
I don’t agree that returning a const reference and using an out reference parameter are semantically identical.
Returning a const reference doesn’t incur any copying, while using an out parameter would most probably require you to copy your internal data into this out parameter.
I am not sure (don’t have the time to try it myself, should be simple though) how BP handles const reference as function return value, though. For example, BP may, if it does support const reference semantics, prevent you perform actions like add or remove items to/from the const reference array. intoxicat3: could you confirm the const reference behavior on your end?
You’re absolutely right, they are not semantically identical and until I just tried it, I believed that this is the only way to ‘return’ a TArray from a blueprint (I don’t actually make many of my functions blueprintcallable)
However, I have just tried returning a const reference and it does indeed work, so that may be more appropriate.
I had the chance to do a test myself, and it seems even though the C++ code compiles with the function returning a const reference array, and the node does show up in BP with the return value as an output pin (the returned const ref array); BUT, any attempts to wire the output array pin to the input pin of some other node, for example the ForEachLoop node, the BP compilation fails with the error saying the direction of the output pin is incompatible or similar.
So it seems that a BP callable function returning a const array reference is essentially not functioning as expected.
The recommended output parameter approach works, but incurs copying.
Also, returning TArray as a value also works, but also incurs copying.