Hello,
What I want to achieve:
A Blueprint Callable function that takes ‘UPARAM(ref) bool&’ as a parameter which can but don’t have to be passed inside of Blueprint Graph (variable don’t have to be pluged into input pin to this node for the graph to compile). And by basing on if the parameter has been passed or not, the function will behave in a slightly different way.
For example I was able to create something ugly like this
void Func(bool& param = *(bool*)0)
{
if (¶m == nullptr)
// do something
}
Above C++ code (sadly, it’s UB), allows to call ‘Func()’ without passing any parameters in it and execute code basing on if the parameter has been passed which is the exact behavior that I’m looking for.
But when I try to declare something similiar as BlueprintCallable UFUNCTION in Unreal, this of course will not compile:
UFUNCTION(BlueprintCallable)
static void Func(UPARAM(ref) bool& param = *(bool*)nullptr);
due to error:
C++ Default parameter not parsed: param “(bool)nullptr”
I’ve also tried to declare global constant variable that would be set as default parameter but the result is the same - compiler throwing “Default parameter not parsed…” Error.
So my question is:
- Is the behaviour that I want to achieve even possible in BlueprintCallable functions?
- Is there any workaround to what I’ve described above?
Thanks in advance! I appreciate any help.
Let me know if something is unclear and I will edit the post.
EDIT - Possible but not exact sollutions:
meta = AutoCreateRefTerm( "param" )
can be specified in the UFUNCTION declaration. This allows Blueprint Node to have default value in pass-by-ref pin. Hovewer with this approach another condition (bool pin) is needed because It is not possible check if actual variable gets passed or not.- TOptional is a data container that exacly fits here BUT TOptional cannot be used as parameter in BlueprintCallable UFUNCTION due to
Error: Unrecognized type 'TOptional' - type must be a UCLASS, USTRUCT, UENUM, or global delegate.
OR at least I don’t know how to use it.