Two problems with singletons.

Hi,

My singleton is made like this:

public class PlayerProgress : MonoBehaviour
{
    //  Singleton
    public static PlayerProgress Instance;

    void Awake()
    {
        // Singleton
        if (Instance != null && Instance != this)
        {
            Destroy(this.gameObject);
        }

        Instance = this;
        DontDestroyOnLoad(this.gameObject);       
    }
}

My problem #1 is when I reload the scene that contains this PlayerProgress 2 times, it gets duplicated and generates another PlayerProgress.

My problem #2: Is it possible to not have an instance of this in every scene and one gets called upon calling PlayerProgress.Instance.something ?

Cheers.

For your first problem after destroying the duplicate instance do not store it as the current instance (since then you lose the first original instance):

void Awake()
     {
         // Singleton
         if (Instance != null && Instance != this)
         {
             Destroy(this.gameObject);
         } else { 
             Instance = this;
             DontDestroyOnLoad(this.gameObject);       
         }
     }

For your second problem you can create an “Initial Scene” where the instance will be added and created and then load the required scene. From the loaded scene you can still access the singleton instance (as it is not destroyed between scenes).
Point is that as long as the scene with the singleton instance is loaded you can access it from any other scene without having an instance of the singleton in these scenes