How can I modify a blueprint variable in C++?

Hello there,

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?

But I mean to modify AND set a variable with one C++ node!
I know it’s kind of unnecessary but it would be a nice little workflow improvement for me.

Make this function float type and return new A value. Then you can set function’s output in blueprint to whatever float you want.

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.

There are no pointers for float type

error : In testlinuxGameMode: Inappropriate '*' on variable of type 'float', cannot have an exposed pointer to this type.

Did you tried using float pointer and return the pointer?