I have a singleton pattern GameManager script in my program that is set to DDOL. In its definition are numerous variables used throughout the game that need to persist between scenes. One such variable contains our client game revision which we validate vs a server.
This is the top of the GameManager Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
[HideInInspector] public string playerName;
[HideInInspector] public string gameRev = "3.84";
…
private static GameManager _instance;
public static GameManager Instance
{
get
{
if (_instance == null) _instance = FindObjectOfType<GameManager>();
return _instance;
}
}
private void Awake()
{
if (Instance != this)
{
Destroy(this.gameObject);
}
else
{
DontDestroyOnLoad(this.gameObject);
}
}
}
Thus this variable is accessed from outside this script via GameManager.Instance.gameRev
The strange behavior we are noticing is that when we change the string literal, the old value is retained.
For example: We updated the “3.84” in the code above from the previous value of “3.82”. We save, and wait for the Unity editor to note the change and allow us to run our game. The value of GameManager.Instance.gameRev is still evaluating to “3.82”. Namely: print(GameManager.Instance.gameRev); produces 3.82 in the Console.
I’ve done a search of the code and this variable is not being referenced anywhere else in the code where it could be changed.
Indeed as additional debugging, I added to the Awake event of GameManager, print(GameManager.Instance.gameRev); and it is still evaluating to 3.82, a value that no longer exists anywhere in our code, and for which this routine HAD to recompile as the print statement was executed.
Any ideas about what I could be missing here?
Incidentally…CHANGING the name of the variable gameRev allows the code to begin working again for a time. I used gameRev2 and it executes as intended showing the proper change…for a time. Then at some point in the future, a change to the string again causes the old value to be retained, and the game runs incorrectly until the variable name is changed again.