This thing is comparing Vector3’s. If ‘true’ it should run MyMethod(). It’s part of a larger for() loop that’s not acting as expected.
if (searchList[search_index] == check_node + new Vector3(offsetDistanceNode, 0, 0))
{
Debug.Log(searchList[search_index] == check_node + new Vector3(offsetDistanceNode, 0, 0));
MyMethod();
}
The weird thing about this is, if the result is ‘true’ I’m seeing "true’ in the console.
If the result is ‘false’ I’m seeing "false’ in the console. When ‘false’ it should skip the part between the { }, or shouldn’t it?
Yes, if(false) means the part in {} gets skipped. As a rule of thumb, computers do not make mistakes and bugs in the base of the laguage are rare to non-existant, so we can basically assert that it’s some human error.
I’m assuming the code does not throw any errors (console) and is not multi threaded?
If you provide a working minimal example, then i could probably answer with a working solution. Like this i dont directly see the problem and there is too much i’m guessing around right now to write a more productive answer. May be anything from floating point precision to missing parenthesis. Also, you can post code examples using the <> code tags.
Try to Debug.Log x y and z of the created and the searchList Vector3 individually. You’re comparing 3 floats so there may be floating point errors. Pretty much the only reason why the Debug.Log could show you it’s false I can think of. Otherwise yeah as Yoreki said show some more code to minimize guessing.
here’s an example of how to compare vectors using Vector3.sqrMagnitude with an offset, which should get rid of floating point precision unreliable behaviour.
Took me all day, but I found it. It was human error (as expected) .A bit too much copy-paste action while building code … forgotten to change the name of a variable somewhere … .