Skip to content

Commit d6349aa

Browse files
committed
Update ObjectPooler.cs
1 parent db90e58 commit d6349aa

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Assets/CustomTools/ObjectPooling/Scripts/ObjectPool/ObjectPooler.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,19 @@ public GameObject SpawnFromPool(PooledObjectType tag, Vector3 pos, Quaternion ro
9292
public void Despawn(GameObject obj)
9393
{
9494
PooledObjectType tag = obj.GetComponent<IPooledObject>().PoolType;
95-
PoolDictionary[tag].Enqueue(obj);
9695

97-
IPooledObject iPooledObj = obj.GetComponent<IPooledObject>();
98-
if (iPooledObj != null) iPooledObj.OnObjectDespawn();
99-
obj.SetActive(false);
96+
if (tag != null)
97+
{
98+
PoolDictionary[tag].Enqueue(obj);
99+
100+
IPooledObject iPooledObj = obj.GetComponent<IPooledObject>();
101+
if (iPooledObj != null) iPooledObj.OnObjectDespawn();
102+
obj.SetActive(false);
103+
}
104+
else
105+
{
106+
Debug.LogWarning("Trying to despawn object which is not pooled !");
107+
}
100108

101109
}
102110

0 commit comments

Comments
 (0)