public void Despawn(GameObject instance) { // Remove the instance from the spawned list. If it was not // found in the spawned list, then do nothing. if (!spawned.Remove(instance)) { return; } // Find the PooledObject component and notify any observers of the despawn var component = instance.GetComponent <dfPooledObject>(); if (component != null) { component.OnDespawned(); } // Disable the instance instance.SetActive(false); // Add the instance back to the "free instance" pool pool.Enqueue(instance); // Reparent the instance to keep the scene hierarchy tree tidy if (allowReparenting && dfPoolManager.Pool != null) { instance.transform.parent = dfPoolManager.Pool.transform; } }