Make array input optional (UFUNCTION)

I have this UFUNCTION (Used as blueprint node):


UFUNCTION(BlueprintPure, meta = (FriendlyName = "Get My Stuff"), Category = "MyCategory")
		static void GetMyStuff(FMyStruct FilterData, TArray<TEnumAsByte<EMyEnum>> Filters, bool& ReturnValue); 

I get compile errors when I don’t pass in an array, and I am wanting to make the underlined parameters be optional. I am currently doing this in order to work-around the problem:
f61346c2cb.png

Any ideas?

1 Like

You need to provide a default value (which could be null), and make it your last argument, or provide an overloaded version of the function that omits that argument.

I’ve seen the AutoCreateRefTerm specifier used for the purpose of making array parameters optional. Documentation is pretty lacking but it appears to create an empty array if the pin is not hooked up. Your function declaration would change to


UFUNCTION(BlueprintPure, meta = (FriendlyName = "Get My Stuff", **AutoCreateRefTerm = "Filters"**), Category = "MyCategory")
static void GetMyStuff(FMyStruct FilterData, TArray<TEnumAsByte<EMyEnum>> Filters, bool& ReturnValue);

Edit: you should also probably change Filters to be a constant reference type if possible.

2 Likes

I am getting an instant crash when compiling the blueprint without the array pin connected now :expressionless: No minidump for the crash either.

I’m unable to reproduce a crash in either 4.9 or 4.10. Which engine version are you using, and can you show how the enumeration used in the array is declared?

Lol, I was using 4.6. I upgraded to 4.10 and it is working fine now. Thanks for helping and taking the time to test for crashes though :smiley:

Haha, ok glad you got it working.

The idea is good but from my experience in practice doesn’t work as long as the function name is the same. If I remember correctly UnrealHeaderTool will complain about it and not even start compiling. Possibly because functions are mapped only by their name which would be ambiguous.