I’ve created a simple boolean variable, DoneLoading, to keep track of when a function is finished executing. DoneLoading is initialized to False, and at the end of the public function, it is set to True.
I call SetSpawnLocation() from another script, and when I print DoneLoading at this point I can see that it IS being set to True. However, when I print out the value of DoneLoading on every OnUpdate() cycle, I’ve found that it gets set back to false and stays false.
EDIT: After further testing, it looks like somehow, inexplicably, the Start() function is being called AFTER SetSpawnLocation(). However, in my main script, GameManager, the gameObject below is instantiated BEFORE I make a call to SetSpawnLocation(). Why would the Start() function be delayed for so long after instantiating?
Also, is there a way to prevent Start() from wiping out and resetting my variables?
private bool doneLoading;
private void SetSpawnLocation(SpawnLocation curLocation)
{
if (curLocation == SpawnLocation.Tropical) {
commonSprites = commonTropicalSkins;
uncommonSprites = uncommonTropicalSkins;
rareSprites = rareTropicalSkins;
ultrarareSprites = ultrarareTropicalSkins;
}
doneLoading = true;
}
void Update() {
print(doneLoading);
}
I’ve searched through my code, and doneLoading is only referenced in 3 places: the initial definition, when it’s set to True inside SetSpawnLocation(), and when I print it out in OnUpdate().
Please please someone help me. I’m going crazy here. This is happening with all non-class variables in this script - they keep being reset when the script updates.