# UFUNCTION optional parameters?

**URL:** <https://forums.unrealengine.com/t/ufunction-optional-parameters/287689>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [July 8, 2014, 7:38pm UTC](https://forums.unrealengine.com/t/ufunction-optional-parameters/287689 "2014-07-08T19:38:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lordink](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lordink](https://forums.unrealengine.com/u/Lordink)\
**Post date:** [July 8, 2014, 7:38pm UTC](https://forums.unrealengine.com/t/ufunction-optional-parameters/287689/1 "2014-07-08T19:38:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![affliction50](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@affliction50](https://forums.unrealengine.com/u/affliction50)\
**Post date:** [July 8, 2014, 8:04pm UTC](https://forums.unrealengine.com/t/ufunction-optional-parameters/287689/2 "2014-07-08T20:04:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Lordink](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lordink](https://forums.unrealengine.com/u/Lordink)\
**Post date:** [July 8, 2014, 8:15pm UTC](https://forums.unrealengine.com/t/ufunction-optional-parameters/287689/3 "2014-07-08T20:15:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Godofdrakes](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Godofdrakes](https://forums.unrealengine.com/u/Godofdrakes)\
**Post date:** [March 23, 2017, 8:12pm UTC](https://forums.unrealengine.com/t/ufunction-optional-parameters/287689/4 "2017-03-23T20:12:25Z")

</div>

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.
