UFUNCTION(BlueprintCallable) in TARRAY function

Im curious why when I have (BlueprintCallable) compiler says “Other Error”, without it compiles without a problem.

	UFUNCTION(BlueprintCallable)
	const TArray<UINT32>& GetWaivesConfiguration();

My Class is Bleprintable, extending from UObject.

Anyone know why this won’t compile?

Basically I can’t expose this function to blueprints.

UINT32 is not a BP supported type, use “int32” (all lowercases).

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.

This will give you:

UFUNCTION(BlueprintCallable, Category="MyCat")
    void GetWaivesConfiguration(TArray<int32>& myArray) {}

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.

noob. Restarting editor show the original function when I changed to int32 instead of UINT32. Thanks guys!

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.

Does BP allow you modify this const reference array then?

intoxicat3: could you confirm the const reference behavior on your end?

– yes, it’s working like a charm.

Just to back this up with an in engine example, if you look at GetOverlappingActors on primitive components it looks just like this:

	UFUNCTION(BlueprintCallable, Category="Collision", meta=(UnsafeDuringActorConstruction="true"))
	void GetOverlappingActors(TArray<AActor*>& OverlappingActors, UClass* ClassFilter=NULL) const;

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.

At least that’s the current status of this.