Blueprint/C++ hybrid Function with optional parameters

Here’s what I’m looking for: A function with optional parameters and default values that is exposed to both blueprints and C++.

I haven’t managed to figure out how to do it without creating a second function entirely like such:



// Blueprint Implementation
UFUNCTION(BlueprintCallable, meta = (DisplayName="My Foo", AutoCreateRefTerm = "MyBaz"))
Foo* BPMyFoo(const Bar& MyBar, const Baz& MyBaz);

 // C++ Implementation
Foo* MyFoo(const Bar& MyBar, const Baz& MyBaz = Baz());


Because UFUNCTION doesn’t accept default values and requires the meta parameter “AutoCreateRefTerm” to make blueprint nodes able to accept no parameters.

Is there any way to get what I need in a single function to rule them all?

1 Like

Pass by value instead of by const ref.

Edit: just tested with a USTRUCT as well and that seems to work too.

I think this really is the only way to do this. You’ll notice a lot of the blueprint equivalents for the native functions in the engine (the ones prefixed with K2_) initialize things to defaults as well before calling functions.

That doesn’t solve the issue. The problem is that to have default values in blueprints, so that you can leave the nodes empty, you need to use the meta descriptor “AutoCreateRefTerm”. This:


// Blueprint Implementation
UFUNCTION(BlueprintCallable, meta = (DisplayName="My Foo", AutoCreateRefTerm = "MyBaz"))
Foo* BPMyFoo(Bar MyBar, Baz MyBaz);

// C++ Implementation
Foo* MyFoo(Bar MyBar, Baz MyBaz = Baz());

has the same problem that I described.
Using the “BPMyFoo” in C++ doesn’t see “MyBaz” as having a default value.

If there is a function in the engine that can do it, could you provide me with the name of the file/function or the filepath to it??