I have a simple Object Pool written exactly like this
List<GameObject> ObjectPool;
public GameObject ObjectToBePooled;
public int ObjectsPooledCount;
void Awake()
{
ObjectPool = new List<GameObject>();
FillObjectPool();
}
void FillObjectPool()
{
for(int i = 0; i < ObjectsPooledCount; i++)
{
GameObject obj = Instantiate(ObjectToBePooled) as GameObject;
DontDestroyOnLoad(obj);
obj.SetActive(false);
ObjectPool.Add(obj);
}
}
I think, invoking the DontDestroyOnLoad(PooledObject) (see line 16) make the PooledObject persists across levels but the ObjectPool won’t. If PooledObject persists across different scenes how can I access each of them? Since, ObjectPool was initialized(ObjectPool = new List();) again by Awake method by loading different scene or reloading the current scene.