private IEnumerator WaitForVesselInitDoneOnLoad()
        {
            while (!FlightGlobals.VesselsLoaded.Contains(vessel) || vessel.vesselName == null || !vessel.parts[0].started)
            {
                yield return(new WaitForFixedUpdate());
            }

            PhysicsHoldManager.AddInstance(this);

            if (physicsHold)
            {
                DoPostOnGoOnRailsTweaks(false, true);
            }
        }
        // Called when a docking/coupling action is about to happen. Gives access to old and new vessel
        // Remove PAW buttons from the command parts and disable ourselves when the vessel
        // is about to be removed following a docking / coupling operation.
        private void OnPartCouple(GameEvents.FromToAction <Part, Part> data)
        {
            Lib.LogDebug($"OnPartCouple on {vessel.vesselName}, docked vessel : {data.from.vessel.vesselName}, dominant vessel : {data.to.vessel.vesselName}");

            // in the case of KIS-adding parts, from / to vessel are the same :
            // we ignore the event and just pack the part.
            if (data.from.vessel == data.to.vessel && data.from.vessel == vessel && physicsHold)
            {
                OnPackPartTweaks(data.from, true, false, true);
                return;
            }

            // "from" is the part on the vessel that will be removed following coupling/docking
            // when docking to a packed vessel, depending on the stock choice for which one is the dominant vessel, we have two cases :
            // A. the dominant vessel is the on-hold vessel
            //    - non-packed parts will be transferred to the resulting (already packed) vessel, we have to pack them
            // B. the dominant vessel is the not-on-hold vessel :
            //    - the resulting vessel isn't packed, and physicsHold is false
            //    - transferred parts will be packed, the others won't

            // from : docking vessel that will be removed
            if (data.from.vessel == vessel)
            {
                PhysicsHoldManager.RemoveInstance(this);

                // case B handling
                if (physicsHold)
                {
                    DisablePhysicsHold(true);
                    VesselPhysicsHold fromInstance = data.to.vessel.GetComponent <VesselPhysicsHold>();
                    fromInstance.delayedPhysicsHoldEnableRequest = true;
                }

                physicsHold = false;
                ClearEvents();
                isEnabled = false;
            }

            // case A handling
            if (data.to.vessel == vessel && physicsHold)
            {
                foreach (Part part in data.from.vessel.Parts)
                {
                    OnPackPartTweaks(part, true, false, true);
                }
            }
        }
 public override void OnUnloadVessel()
 {
     PhysicsHoldManager.RemoveInstance(this);
     ClearEvents();
 }