Skip to content

Commit d60f057

Browse files
authored
Update PoolExtensions.cs
1 parent 371f90f commit d60f057

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

PoolExtensions.cs

+9-8
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,16 @@ public static void Despawn(this Poolable instance) =>
6161
instance.ReturnToPool();
6262

6363
/// <summary>
64-
/// Use this method only with Instances of Prefab
64+
/// Use this method only with Instances of Prefab. Slow in terms of perforamance, use Despawn with Poolable param instead
6565
/// </summary>
66-
public static void Despawn(this GameObject instance) =>
67-
instance.GetComponent<Poolable>().ReturnToPool();
66+
public static void Despawn(this GameObject instance)
67+
{
68+
var poolable = instance.GetComponent<Poolable>();
6869

69-
/// <summary>
70-
/// Use this method only with Instances of Prefab
71-
/// </summary>
72-
public static void Despawn(this Transform instance) =>
73-
instance.GetComponent<Poolable>().ReturnToPool();
70+
if (poolable != null)
71+
poolable.ReturnToPool();
72+
else
73+
Object.Destroy(instance);
74+
}
7475
}
7576
}

0 commit comments

Comments
 (0)