I’ve been looking everyone for an answer to this, but I’m guessing this is just too basic of a question to be asked. I’m really new to C++ and UE4 so I’m hoping to get some help.
Basically, I’m looking for the C++ equivalent of the set variable node in blueprints. So far I’ve been working on functions and calling for them in blueprints. I would set the return value of the function using the “set variable” node in blueprints in order to use the value for other functions. For some reason, without doing this, the return value just disappears and I can’t use it for the future.
I’m wondering if there’s a way to do this in C++ instead of blueprints, as it would keep everything cleaner and easier to access.
For example, if I declare a function and an int32 in .h:
You’re on the right track. The set functions in blueprints can be recreated by making a generic Set function as most programmers use but also returning the value.
Lets take Variable A and set it to the value in Variable B, both are floats in this case. First we declare it all:
At this point, you should have a set function with an input for NewValue and an output. You can plug VariableB into the input to set VariableA to its value. It will lack execution pins due to being blueprint pure.
If you want it to work like a true set node, you’ll need to make it into a BlueprintNativeEvent, and follow the syntax of the _Implementation functions. This will add the execution pins.
Hi! Thanks for the response. The BlueprintNativeEvent was towards what I was looking for. I’m not sure what I’m doing wrong, but here’s my BP below. When I press the test key, it would cast to the instance and then call on the function to set the number based on the return. Then to test if the variable was actually set to the value in the function, I use a second test key, but it always returns as 0.
I mean the code is super simple. I’m literally just setting the variable to the value of 30 as a test.
In the function that you just posted, you’re setting the parameter (the value that is being passed into the function) to 30 and returning the original variable, which hasn’t been changed. This is why it is not changing when the function is called.