Weird C# boolean behavior

Hi guys,

I noticed that for some unknown reason, C# booleans in MonoDevelop/Unity become unreliable in some MonoBehaviours.

I noticed that even though I already set a certain variable explicitly as ‘false’, it still goes through in an ‘if’ statement. Attached is a screenshot of a test that I did. I stepped into the code and as you can see at the Watches below, the variable testX is currently set to ‘false’, but as you can also see, the program went inside of the ‘if’ statement.

Is anybody else experiencing this problem? Any workarounds?

516786--18357--$WeirdBooleanBehavior.png

There’s nothing unreliable about booleans; the value in the inspector overrides anything you set in the script.

–Eric

Without the whole code its hard to say much.
I’ve never seen any such behavior so far.

What unity version is this and is it the brought along version of mono develop so you are not hit by missbehaviour due to incompatible plugin / debuggers etc in your value watch there?

Also did you ensure that the class with this behaviour does not extend a class with the same value in and thus leading to missbheaviour where the value is taken from? (as you don’t override it explicitely or “new” it)

@Eric5h5 : The variable is not being exposed to the inspector.

@dreamora : The class where this code resides only inherits from MonoBehaviour. Also the test method/function that’s in the screenshot is being called in the Update method.

I just tested on a new scene and ran the same code. It worked fine. Not sure if it is because of the complexity or whatever, but it really is just a simple construct even if it is under tons ans tons of code. The mere fact that the debugger is showing that it is currently ‘false’ but is treated like it is set to ‘true’ is very very weird.

not weird but potentially related to the debugger showing trash in the local list there.

@dreamora : Yeah… seems to be the debugger that was causing it. I restarted Unity 3.2, then voila! Back to normal. sigh

I should always remember one of the major tenets in programming : “When in doubt, RESTART!”

Oh right, I forgot the default for C# is private.

–Eric