At the beginning of my app I have a global variable gameData
which is declared and instantiated as:
GameData gameData = GameData();
Later I want to clear the gameData
variable and re-instantiate/reset the variable with a clean instance of GameData
. I do this by calling a function:
void ResetGameData() {
gameData = new GameData();
}
But that's not clearing the gameData
variable. All the old values are remaining. Is there a better way of doing this?
The issue was I was instantiating a class within a class, and that syntax was incorrect so the sub-class was retaining its previous data. The rest of the variable was re-instantiated correctly.