Quantcast
Channel: Questions in topic: "crash"
Viewing all articles
Browse latest Browse all 2383

Object Pooling Crashes Unity

$
0
0
- 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 pools; public Dictionary> poolDictionary; // Start is called before the first frame update void Start() { poolDictionary = new Dictionary>(); foreach(Pool pool in pools) { Queue objectPool = new Queue(); 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; }

Viewing all articles
Browse latest Browse all 2383

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>