Comparing Variables

I’m trying to put together a small system that checks if my variables change. I have 2 variables X and Y that need to be checked and 2 others which are the old/previous values.

On the image, there are 2 Equal Operators and my problem here is that it makes sense for some reason. If I compare the X value and connect that Equal Op. to the Branch only the “X old” value will be updated and if I change the Y’s value it will update only when I change the X’s value. Same with the “Y”.

If I disconnect the condition from the Branch and I use a simple False value both the X & Y values update correctly.

Do I miss something here or is this how it should work? I thought this shouldn’t affect the rest of the blueprint at all.

FIrst – you can set the x-old and y-old values always, without a comparison.
In this case, executing the comparison/branch node will take more time than just always updating the values.

Second – if you want to separately update the X and the Y values, you need to separate branches, that go to the separate updates. The Sequence node can be helpful for laying this out.

Third – if you want to update both variables, if either of them changed, then you can use an “AND” node to merge the “x is the same” and “y is the same” – if they BOTH are the same, no need to update either of them.

But, in this case, just always update both of them, because it will have the same result. Then again, because you just updated X and Y, too, updating the old ones doesn’t really seem that helpful, as they will always have the same result as the just-updated X and Y, so it kind-of depends on what you want to do with the values.

2 Likes

Here’s a macro you might find useful:

image

For debugging stuff like this, it is helpful to set some input events to trigger each part of what you want to test, and have some print strings display the output. Isolate just one thing at a time to understand what is happening at every step of the code. If you have too many balls to juggle at the same time, you’ll drive yourself crazy :).

3 Likes

The reason I do the comparison is that I only want the code to go through if at least one of them is changed, and if so the branch returns False.

This is what I did before, and it works the way I wanted to, also looks like the way you described, so I’m pretty sure this is also how you meant to do it.

The only thing that is unclear for me is still from my original post. Why did it matter which (x or y) equal boolean did I use for the branch? If I used the X one then only the X - old got updated, and the same with the y.

I didn’t know about the existence of this macro. Previously I used a simple Print String with an Append function for debugging. This will be helpful in the future, thanks!

I’m a little confused with what you’re trying to achieve compared to the screenshot, but it looks like you could try a sequence and just check them both with a branch of their own and run them back into the same node after the last “Set Y-Old” variable.

If they’re setting without a branch condition in scope I’m pretty sure it’s just an empty node and they’re just running straight through like its not there. If it’s working like that its probably luck that the values just happen to not be == to the checks lol.

Pretty sure that’s not what actually happened. If you only used one variable in the test, then it updates both variables when that variable changes.
You could add PrintString saying “set x-old to … and y-old to …” after the branch, to see what’s going on in a little more detail.
It may be that this function gets called more than once, for example?

I’m sure it sounds strange, but I even tested the runtime values before my post. I checked the values with Print String nodes and with the debug option in the engine to see the values of the variables. And the only connection I found of which variable got updated, is the used condition with the branch.

Although it was solved with an and boolean (above showed), this phenomenon was strange, that’s why I posted this, and maybe someone has an idea of what might have happened.

And yes it is connected to an Event Tick.