Branch node doesn't return correct value
So I'm doing my first Match game and the logic I use to define what to spawn when matching two actors is taking a Float Variable from each actor and adding them together. This works as intended for every match except the first one (2.3) and even though I'm debugging with Print String to verify that I get the result 2.3 it will still just return everything False (and thus not spawning anything)
Can anyone think of something I'm doing wrong? I tried simply switching the True and False Execs but that just makes EVERYTHING to turn into the object intended for 2.3 :p I also tried putting the first Branch node in the "bottom of the stack" but that just returned the same problem.
You are likely running into floating point round off errors. They don't happen as often when simply adding two float's, but can still happen sometimes.
When you perform math operations on multiple float values you will sometimes get a value that is almost, but not exactly the value you want.
In this case 1.2 + 2.1 could potentially return 2.300001 (example only). The reason for this is float's only have about 6 decimal places worth of precision before they start running into round off errors. The precision is good enough for most uses in a game engine, but using them in a math equation will not always produce the exact value you are looking for.
For that reason you should try to avoid using the "float == float" node, there is no way to guarantee it will be equal. You should use less/greater than or equals, or even two integers (one for the whole number, the other for the remainder) instead to ensure it's accurate.
Hope that helps,
Follow this question
Once you sign in you will be able to subscribe for any updates here