- Home /
The question is answered, right answer was accepted
true initialized bool is false after compiling
Hey, i have a really strange issue. The bool "firstFrame" is initialized to true, but after compilation is is set to false. The if condition is allways false in play mode and the Debug.Log is never reached.
Could this have anything to with the fact that the class is a child of an abstract class? Am I missing something?
public class ActionAgentWalkTo : AAction {
private bool firstFrame = true;
public override bool Execute() {
if (firstFrame) {
Debug.Log("First Frame")
firstFrame = false;
}
...
}
}
Answer by Jazzhorse · Apr 27, 2020 at 12:02 PM
Okay, I found the issue. An Instance of this class is living in the scene and the value didn't get reset for it. When I delete the instance and add a new one, the bool is set to true.
You could have saved your self some trouble here if you had either
1) put [SerializeField] above the field so that it will show in the inspector and you can see and set the value their
2) you made the field public ... why is it private?
I tested both. Didn't work either. The variable got changed outside of play mode, so it didn't reset itself. I just added an Init function that resets the variable, when needed. Now it works fine.