// This will despawn a clone and add it to the cache public void FastDespawn(GameObject clone, float delay = 0.0f) { if (clone != null) { // Delay the despawn? if (delay > 0.0f) { // Make sure we only add it to the marked object list once if (delayedDestructions.Exists(m => m.Clone == clone) == false) { var delayedDestruction = LeanClassPool <DelayedDestruction> .Spawn() ?? new DelayedDestruction(); delayedDestruction.Clone = clone; delayedDestruction.Life = delay; delayedDestructions.Add(delayedDestruction); } } // Despawn now? else { // Add it to the cache cache.Add(clone); // Messages? SendNotification(clone, "OnDespawn"); // Deactivate it clone.SetActive(false); // Move it under this GO clone.transform.SetParent(transform, false); } } else { //Debug.LogWarning("Attempting to despawn a null clone"); } }