noodle run Posted October 12, 2025 Share Posted October 12, 2025 I made a MOD that removes asteroids The process is as follows: 1.Delete Crop, Health, Comet (copy the sandbox tool code) 2.traverse the asteroid's cells 3.delete Pickupable, delete any existing Storage components 4.finally delete the Grid.Objects component 5.Call Grid.FreeGridSpace 6.Delete WorldContainer component Is this a complete cleanup? public void UnRegAsteroid() { ClusterManager.Instance.UnregisterWorldContainer(world); } private void FixClusterTravelers(int world_id, AxialI world_loc) { foreach (ClusterTraveler clusterTraveler in Components.ClusterTravelers.Items) { if (clusterTraveler == null || clusterTraveler.IsNullOrDestroyed()) continue; Debug.Log($" Test TestTestTestTestTestTestTestTest {clusterTraveler.GetComponentInParent<ClusterDestinationSelector>().name} "); ClusterDestinationSelector selector = clusterTraveler.GetComponentInParent<ClusterDestinationSelector>(); if (selector.GetDestinationWorld() == world.id) { selector.SetDestination(world_loc); } } } private void ClearWorld(WorldContainer world, Action<float> report) { ConduitFlow_DO_NOT_Dump.do_not_dump = true; HashSetPool<GameObject, SandboxDestroyerTool>.PooledHashSet pooledHashSet = HashSetPool<GameObject, SandboxDestroyerTool>.Allocate(); foreach (Crop cmp in Components.Crops.Items) { if (Grid.WorldIdx[Grid.PosToCell((KMonoBehaviour)cmp)] == world.id) pooledHashSet.Add(cmp.gameObject); } foreach (Health cmp in Components.Health.Items) { if (Grid.WorldIdx[Grid.PosToCell((KMonoBehaviour)cmp)] == world.id) pooledHashSet.Add(cmp.gameObject); } foreach (Comet cmp in Components.Meteors.GetItems(world.id)) { if (!cmp.IsNullOrDestroyed()) pooledHashSet.Add(cmp.gameObject); } foreach (GameObject original in (HashSet<GameObject>)pooledHashSet) Util.KDestroyGameObject(original); pooledHashSet.Recycle(); for (int cell = 0; cell < Grid.CellCount; cell++) { report.Invoke((cell + 1f) / Grid.CellCount); if (Grid.WorldIdx[cell] != world.id) continue; foreach (ObjectLayer layer in Enum.GetValues(typeof(ObjectLayer))) { GameObject go = null; try { go = Grid.Objects[cell, (int)layer]; } catch { } if (go == null) continue; if (layer == ObjectLayer.Pickupables) { ObjectLayerListItem objectLayerListItem = go.GetComponent<Pickupable>().objectLayerListItem; if (objectLayerListItem != null) { while (objectLayerListItem != null) { GameObject gameObject2 = objectLayerListItem.gameObject; objectLayerListItem = objectLayerListItem.nextItem; Util.KDestroyGameObject(gameObject2); } } } Storage storage_object = go.GetComponent<Storage>(); if (storage_object != null) { foreach (var _array in storage_object.items.ToArray()) { if (_array == null) { storage_object.items.Remove(array); continue; } storage_object.items.Remove(_array); Util.KDestroyGameObject(_array); } } try { Util.KDestroyGameObject(go); } catch (Exception e) { Debug.LogWarning($"[Purge] Destroy failed: {go.name} @cell {cell} | {e}"); } } } ConduitFlow_DO_NOT_Dump.do_not_dump = false; FixClusterTravelers(world.id, world_loc); Grid.FreeGridSpace(world.WorldSize,world.WorldOffset); Util.KDestroyGameObject(world.gameObject); } Link to comment https://forums.kleientertainment.com/forums/topic/168393-will-this-cause-a-memory-leak/ Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now