Object Pooling Crashes Unity
I made an Object Pooling script from Brackeys video, it was working at first but one day after it started to crash unity. If I remove the Object Pooler, unity works fine. No error in console.
It might be about setting an object's setActive function to false while on animation, I removed animator of the object and still crashes.
Also Unity's Object Pooler scripts crashes too. Website: https://learn.unity.com/tutorial/introduction-to-object-pooling
[System.Serializable] public class Pool { public string tag; public GameObject prefab; public int size; } #region Singleton public static ObjectPooler Instance; private void Awake() { Instance = this; } #endregion public List<Pool> pools; public Dictionary<string, Queue<GameObject>> poolDictionary; // Start is called before the first frame update void Start() { poolDictionary = new Dictionary<string, Queue<GameObject>>(); foreach(Pool pool in pools) { Queue<GameObject> objectPool = new Queue<GameObject>(); for (int i=0; i< pool.size; i++) { GameObject obj = Instantiate(pool.prefab); obj.SetActive(false); objectPool.Enqueue(obj); } poolDictionary.Add(pool.tag, objectPool); } } public GameObject SpawnfromPool (string tag, Vector2 position, Quaternion rotation) { GameObject objecttoSpawn = poolDictionary[tag].Dequeue(); objecttoSpawn.SetActive(true); objecttoSpawn.transform.position = position; objecttoSpawn.transform.rotation = rotation; poolDictionary[tag].Enqueue(objecttoSpawn); return objecttoSpawn; }
Comment