Calling a variable from another script overwrites it?

Am just doing that. I have a bool: [HideInInspector] public bool exampleBool = true;
Originally It was only true if it was marked in the inspector, but I changed it to this so it would always be true. Anyway, am calling it from its own script several times just to debug and is always true, as it should. But am also calling it from the other script and is always false. In fact, am not even changing its value.
I know that the problem is that the second script overwrites the true value to false becase I created this:

public void testValue()
print("exampleBool: " + exampleBool);

Now, this is the thing: am calling this void from both its own script and another one, both in Update(); The result from its own is true (as it should), but the other is false.

So this is why am assuming that calling the variable from other script overwrites it, but I don´t know why.

So a few things:

  • If your bool is always true then it probably doesn’t need to exist.
  • If it needs to be configurable but constant make it a constant.
  • Bools are structs and have a default value and by default a bool is false if you are accessing it before its explicitly set then it will be false. So either set it to true in its declaration or make sure you are accessing it after it is set.

The first script is correct. I would just do in Start() { exampleBool = true;} and in the second script in Update(){ Debug.Log(FirstScript.exampleBool); } Hope it helps a bit