private void RecursivelyRemoveNetObject(NetObject obj, bool childRemoval = false) { if (obj.HasChildren) { foreach (var child in obj.Children) { RecursivelyRemoveNetObject(Get(child), true); } obj.Children.Clear(); } if (obj.HasParent && !childRemoval) { Get(obj.ParentID).RemoveChild(obj.ID); } var packet = new NetDestroyPacket { NetID = obj.ID, DestroyData = obj.DestroyData }; if (obj.SendToAllClients) { server.SendToAllClients(packet); } else { server.SendToSingleClient(packet, obj.ClientID); } obj.RemoveSyncListener(OnObjectSync); removedObjects.Add(obj.ID); obj.Alive = false; netObjects.Remove(obj.ID); netObjectPool.Recycle <NetObject>(obj); }
private void OnNetDestroy(NetDestroyPacket obj) { //Debug.Log($"[Client] - NetObject destroyed with id {obj.NetID}"); DebugUtils.Assert(NetObjectExists(obj.NetID), $"Net object with id {obj.NetID} doesn't exist on the client."); var netObj = netObjects[obj.NetID]; netObj.DestroyData = obj.DestroyData; // We need to recursively destroy objects and clean up references RecursivelyDestroyNetObject(netObj); }