Weird behavior on scene reset

So when my hero dies, the scene is restarted with a simple SceneManager.LoadScene(sceneName[sceneCount]);

I initialize some pools in the code below. The only one that gets initialize on the reset is ActiveDustPool. Any idea what’s going on?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class LivingRoomSetup : MonoBehaviour {

    public GameObject coinFab;
    public GameObject dustFab;
    public GameObject dustBunnyFab;
    public GameObject toastFab;
    public Text hitCountFab;


    public GameObject result;


    // Use this for initialization
    void Start () {
        //hide result
        result.SetActive(false);

        //start the pool
        CoinPool.init(coinFab, 5);

        ActiveDustPool.init(dustFab, 10);

        DustBunnyPool.init(dustBunnyFab, 10);

        ToastPool.init(toastFab, 5);

        HitCountPool.init(hitCountFab, 5);

        Camera.main.GetComponent<SimpleBlit>().FadeToScreen();


    }
    

}

So… what is the weird behaviour you’re seeing? Are you getting errors or exceptions thrown?

Hard to say what’s going on without knowing what the init function does.

No errors in restart except when the script tries to get an object pool that doesn’t exist.

This is the typical init function

public static int poolNum;
    public static GameObject pooledObj;
    public static List<GameObject> dustPool;
    //public static ActiveDustPool current;


    // Use this for initialization
    public static void init (GameObject prefab, int initQuantity)
    {

        //current = this;
        pooledObj = prefab;
        poolNum = initQuantity;

        dustPool = new List<GameObject> ();

        //init pool
        for (int i = 0; i < poolNum; i++) {
           
            GameObject obj = (GameObject)GameObject.Instantiate (pooledObj);
            obj.SetActive (false);
            dustPool.Add (obj);

        }
        //just set the gameobject to obj.SetActive(false) to send back to pool


    }

I do notice something. I moved the pool scripts into a folder for organization except I forgot to move ActiveDustPool.cs into the folder. I’ll see if reattaching the script will help.


I tried reattaching and moving the files out of the folder with no change in result.

Oh I found the issue.
In my other pools I added a null conditional.

if(bulletPool == null) {
     //init pool
            for (int i = 0; i < poolNum; i++)
            {

                GameObject obj = (GameObject)GameObject.Instantiate(pooledObj);
                obj.SetActive(false);
                bulletPool.Add(obj);

            }
}

When reset or going to a new scene, The List dustPool isn’t remove but the gameObject instances are delete. I guess I need to remember to clean up when going to new scenes. I thought it was automatic.