UFUNCTION optional parameters?

Hi guys,

I am writing a class, and I would like to use some UFUNCTIONs in it, which will have default argument values (so that you may or may not specify them, while calling functions from Blueprints). How do I do that? So far, I did not find a single line in engine code or in docs, that explain this optional parameter specifier.

I have tried these versions:

UFUNCTION(BlueprintCallable, Category = Mechanics)
void forceInitItem(uint16 itemLvl = 1);

this throws compilation error from UBT: “C++ Default parameter not parsed: itemLvl "1"

FUNCTION(BlueprintCallable, Category = Mechanics)
void forceInitItem(optional uint16 itemLvl = 1);

This simply gives error like “unrecognized keyword “optional”

So, what’s the right way?

Change uint16 to int32. For some reason not all parameter types seem to like taking default values. int32 will at least give you the same range of positive values.

1 Like

Whoa this is a cryptic piece of information :slight_smile:
Thanks man, that works now.

1 Like

To be more specific, not all native types have blueprint equivalents. The BP type ‘Integer’ is int32. The error isn’t ‘uint16 can’t have a default value’ but that you are trying to provide a type to blueprint that it can’t understand. If you removed the ‘BlueprintCallable’ part of the function you’d find the error to be resolved as well.

1 Like