About singletons error check

in the singleton :

if (Instance != null)
        {
            Debug.LogError("There's more than one UnitActionSystem! " + transform + " - " + Instance);
            Destroy(gameObject);
            return;
        }

Shouldn’t we check if Instance is not null AND is not ‘this’? Because if we somehow already registered with this object we’d end up deleting ourselves, thus making Instance null? (especially it seems this could happen if we use Dontdestroyonload)?

This couldn’t happen, because Awake() is only called once on a given object by Unity, even if you use DontDestroyOnLoad.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms