Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Public Lists persist in Singleton after level re-load

Discussion in 'Scripting' started by Artem-Koval, Jul 8, 2014.

  1. Artem-Koval

    Artem-Koval

    Joined:
    Mar 18, 2011
    Posts:
    6
    Hi!

    I've got interesting problem.

    Basically I've got singleton such as
    Code (CSharp):
    1. public class Manager: Singleton<Manager>
    2. {
    3. //...
    4. public List<GameObject> SomeObjects;
    5. //...
    6. }
    Singleton pattern can be found here http://wiki.unity3d.com/index.php/Singleton

    I've got following flow:

    1. Start level 002.
    2. Singleton SomeObjects list gets populated during play.
    3. Call menu to load another level 001 (think of it as some kind of pre-level tuning). Manager is not present there.
    4. Call menu from level 001 to load level 002.
    5. Bug - SomeObjects list contains objects from previous run. And objects are null (at least SomeObjects == null is True).

    I tried to disable DoNotDestroyOnLoad from base pattern, forcefully clear list on OnLevelWasLoaded, in Start() - nothing helps. Really don't know what can cause this strange behaviour. Any help is welcome.

    Thanks, Artem.
     
  2. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
  3. Artem-Koval

    Artem-Koval

    Joined:
    Mar 18, 2011
    Posts:
    6