public virtual bool Detach(bool updateGroup = true, bool reattach = true) { if (m_constraint == null) { return(false); } Debug.Assert(m_constraint != null); Debug.Assert(m_rotorGrid != null); Debug.Assert(m_rotorBlock != null); var tmpRotorGrid = m_rotorGrid; CubeGrid.Physics.RemoveConstraint(m_constraint); m_constraint.Dispose(); m_constraint = null; m_rotorGrid = null; if (m_rotorBlock != null) { m_rotorBlock.Detach(); } m_rotorBlock = null; // The following line is commented out on purpose! If you move the motor between grids (e.g. after splitting), // you have to remember the attached rotor somehow. This rotorBlockId is how it's remembered. //m_rotorBlockId = 0; if (updateGroup) { OnConstraintRemoved(GridLinkTypeEnum.Physical, tmpRotorGrid); OnConstraintRemoved(GridLinkTypeEnum.Logical, tmpRotorGrid); } if (reattach) { // Try to reattach, if the block will still live next frame. This fixes missing attachments when splitting grids NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME; } if (tmpRotorGrid != null) { tmpRotorGrid.OnPhysicsChanged -= cubeGrid_OnPhysicsChanged; } return(true); }
public virtual bool Detach(bool updateGroup = true) { if (m_isWelding == false) { UnweldGroup(); } var tmpRotorGrid = m_rotorGrid; if (updateGroup) { OnConstraintRemoved(GridLinkTypeEnum.Physical, tmpRotorGrid); OnConstraintRemoved(GridLinkTypeEnum.Logical, tmpRotorGrid); } if (m_constraint == null) { return(false); } Debug.Assert(m_constraint != null); Debug.Assert(m_rotorGrid != null); Debug.Assert(m_rotorBlock != null); CubeGrid.Physics.RemoveConstraint(m_constraint); m_constraint.Dispose(); m_constraint = null; m_rotorGrid = null; if (m_rotorBlock != null) { m_rotorBlock.Detach(m_welded || m_isWelding); } m_rotorBlock = null; m_isAttached = false; UpdateText(); return(true); }