public override void Close() { GameLogic.Close(); //doesnt work in parallel update //Debug.Assert(MySandboxGame.IsMainThread(), "Entity.Close() called not from Main Thread!"); Debug.Assert(MyEntities.UpdateInProgress == false, "Do not close entities directly in Update*, use MarkForClose() instead"); Debug.Assert(MyEntities.CloseAllowed == true, "Use MarkForClose()"); //Debug.Assert(!Closed, "Close() called twice!"); //Children has to be cleared after close notification is send while (m_entity.Hierarchy.Children.Count > 0) { MyHierarchyComponentBase compToRemove = m_entity.Hierarchy.Children[m_entity.Hierarchy.Children.Count - 1]; Debug.Assert(compToRemove.Parent != null, "Entity has no parent but is part of children collection"); compToRemove.Container.Entity.Close(); m_entity.Hierarchy.Children.Remove(compToRemove); } //OnPositionChanged = null; CallAndClearOnClosing(); MyEntities.RemoveName(m_entity); MyEntities.RemoveFromClosedEntities(m_entity); if (m_entity.Physics != null) { m_entity.Physics.Close(); m_entity.Physics = null; m_entity.RaisePhysicsChanged(); } MyEntities.UnregisterForUpdate(m_entity, true); if (m_entity.Hierarchy.Parent == null) //only root objects are in entities list { MyEntities.Remove(m_entity); } else { m_entity.Parent.Hierarchy.Children.Remove(m_entity.Hierarchy); //remove children first if (m_entity.Parent.InScene) { m_entity.OnRemovedFromScene(m_entity); } MyEntities.RaiseEntityRemove(m_entity); } if (m_entity.EntityId != 0) { MyEntityIdentifier.RemoveEntity(m_entity.EntityId); } //this.EntityId = 0; Debug.Assert(m_entity.Hierarchy.Children.Count == 0); CallAndClearOnClose(); Closed = true; }