I’m trying to make a simple BlueprintCallable function node that can modify the variable that I input into it.
Normally I would just return the modified variable then use the “Set” node to assign it to the variable I need in blueprint but I was hoping I can avoid the extra step for convenience.
I made this super simple test:
.h file
/** Increments a float*/
UFUNCTION(BlueprintCallable, Category = "Math|Float")
static void IncrementFloat(float A, float Step);
.cpp file
void UMathTest::IncrementFloat(float A, float Step)
{
A += Step;
}
And as I expected it didn’t work.
Is there any easy way to do this from C++ without having to create a UPROPERTY variable?
Use reference then. YourFunction(float &A, float B)
But it probably won’t work (I guess that A will be 0). I’ll try.
UPDATE: I tried and function works but at the 2nd time I called it. First time it set A to 0. Probably because Set node stands AFTER function in blueprint function doesn’t have memory address for its first run. So one node solution is impossible, you have to use GET node and SET node.