Skip to content

Commit 4e17d64

Browse files
authored
Update PoolExtensions.cs
1 parent 7abd775 commit 4e17d64

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

PoolExtensions.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,16 @@ public static T Spawn<T>(this GameObject prefab, Vector3 position, Quaternion ro
5757
/// <summary>
5858
/// Use this method only with Instances of Prefab
5959
/// </summary>
60-
public static void Despawn(this Poolable instance) =>
60+
public static void Despawn(this Poolable instance)
61+
{
62+
if (!instance.IsPooled)
63+
{
64+
Object.Destroy(instance.gameObject);
65+
return;
66+
}
67+
6168
instance.ReturnToPool();
69+
}
6270

6371
/// <summary>
6472
/// Use this method only with Instances of Prefab. Slow in terms of perforamance, use Despawn with Poolable param instead
@@ -68,9 +76,19 @@ public static void Despawn(this GameObject instance)
6876
var poolable = instance.GetComponent<Poolable>();
6977

7078
if (poolable != null)
79+
{
80+
if (!poolable.IsPooled)
81+
{
82+
Object.Destroy(instance);
83+
return;
84+
}
85+
7186
poolable.ReturnToPool();
87+
}
7288
else
89+
{
7390
Object.Destroy(instance);
91+
}
7492
}
7593
}
7694
}

0 commit comments

Comments
 (0)