I use the following template to make my singleton in Unity
public class BlobManager : MonoBehaviour
{
public static BlobManager instance {get; private set;}
void Awake ()
{
if(instance != null && instance != this)
Destroy(gameObject);
instance = this;
DontDestroyOnLoad(gameObject);
}
public void SomeFunction()
{
if (this != instance)
Debug.Log("They're Different!")
}
}
They always turn out to be different, as shown in SomeFunction(). When I set the value locally for the BlobManager class, and the other is to use the static "instance" of var like this:
foo = "bar";
BlobManager.instance.foo = "foo";
the foo value observed in the debugger at the breakpoint in the class will always be "bar". But when other classes try to access the same variable, it will be "foo".
I'm not sure how to look at memory addresses in Monodevelop, but I'm sure that thisthey this.instancewill have different memory addresses. Is there something wrong with my singleton pattern? I tried other templates with the same result.