Getting float errors in Blueprint

Hi - I wonder if someone can help me because I think I’m going crazy. I’ve got a PDI controller written in C++. It generally works well but when I use it to control pitch of the craft I take the result and add a force to the front and subtract it from the back. All good normally. But for some reason, if I just take the result out of the controller and negate it then add it back to itself (as a debug) it can give me a result other than 0. This makes no sense. Screen shot is attached below of the simple blueprint debug moment. Can anyone explain how the output of that string could be non-zero??

This is most likely happening because of NegateFloat node (screenshot below) and because of how the execution flow works in blueprints.

image

This node changes the value by reference (negating the value of PID ROLL OUT variable), so by the time you get to the PrintString, the output pin of SetVariable node will always return already negated value, exactly the same one as output pin of NegateFloat.

So in your case the “+” node basically adds the two same values (as they reference the same variable).

I can even easily reproduce this behavior:

image


Not sure what exactly you want to do here?

Probably, negating a variable is not what you intended.
If that’s true, do this:

If you really wanted to negate a variable by reference, do this instead:

Either of those will produce the result that you expected in the first place:

image


Next time, when such issue occurs, I suggest using breakpoints and stepping through the nodes:


Hope, this helps

Thanks. I had just now determined that a multiply by -1 didn’t produce the same error, so maybe I misunderstand the use of “Negate”, which I thought would do the same thing but didn’t produced the same result.

1 Like