What's the trick to defining an array param in a UFUNCTION?

I have 2 UENUM enumerated types: EGameResource and EGameResourceTypes.

UFUNCTION( BlueprintCallable, Category=MyGame)
void DefineResourceTypes( TArray<EGameResource> & Resources, EGameResourceTypes ResourceType );

The compiler sadly informs me that

OCResourceConversionDefinitions.h(26): error C2664: ‘void AOCResourceConversionDefinitions::DefineResourceTypes(TArray &,EGameResourceTypes)’ : cannot convert argument 1 from ‘TArray,FDefaultAllocator>’ to ‘TArray &’

What on earth is going on? How am I supposed to define an array of enums for a function exposed as a UFUNCTION?

OK – I seem to be able to work around it by changing the array to a TEnumAsByte:

void DefineResourceTypes( TArray<TEnumAsByte<EGameResource> > & Resources, EGameResourceTypes ResourceType );

Unfortunately, I am seeing that the array is, for some reason, getting treated as an OUTPUT parameter instead of the INPUT parameter it’s actually intended to be. What gives?

8816-array_as_output.png

If you add const in front of your reference type parameter it will make it an input on the blueprint:

void DefineResourceTypes( const TArray > & Resources, EGameResourceTypes ResourceType );

By default, pass by reference parameters are treated as outputs on blueprint nodes.

Thanks – works like charm!

If you want the array to remain editable, try the UPARAM(ref)