Skip to content

Fix the auto-pilot breaking after revert to launch#958

Merged
djungelorm merged 1 commit into
mainfrom
autopilot-revert-fix
Jul 17, 2026
Merged

Fix the auto-pilot breaking after revert to launch#958
djungelorm merged 1 commit into
mainfrom
autopilot-revert-fix

Conversation

@djungelorm

@djungelorm djungelorm commented Jul 17, 2026

Copy link
Copy Markdown
Member

The auto-pilot stopped working after a "Revert to Launch": with it engaged, reverting left it unable to drive the vessel, and it would not re-engage (shown greyed out) when the script was re-run, until the game was restarted.

Root cause. AutoPilot cached its AttitudeController at construction — the only piece of its state not resolved live by vessel id (everything else goes through InternalVessel). The controllers live in a static per-vessel registry that is recreated when the flight scene reloads. A client that keeps its auto-pilot object across the revert — the usual pattern, set once at the top of a script — keeps reusing the same server-side object, now pointing at a controller orphaned from the recreated registry: Engaged is set on the orphan, but the per-tick pilot loop consults the live registry and never drives the vessel. Only restarting the game, which drops the connection and its cached objects, recovered it.

Fix. Resolve the controller live from the registry on each access, like InternalVessel, so an auto-pilot object re-binds to the current controller after a reload. Also tear down per-vessel pilot state on onVesselDestroy — detach the fly-by-wire callback, revoke any RemoteTech sanctioned pilot, and drop the vessel's registry entries — instead of relying only on the wholesale clear at scene teardown, which left delegates bound to dead vessels.

Testing. Adds TestAutoPilotRevertToLaunch: it engages the auto-pilot, reverts to launch, and reuses the same auto-pilot object to confirm the pilot loop drives the recreated vessel. A reverted craft sits on the launch pad and cannot be slewed to a target, so the test relies on a driven auto-pilot forcing the SAS action group off every tick. Verified failing before the fix and passing after, with the existing auto-pilot tests still passing.

AutoPilot cached its controller instead of resolving it live by vessel id, so a
client that kept the object across a revert was left driving a controller
orphaned from the registry the reload recreates — it read as engaged but no
longer flew the vessel until a game restart. Resolve the controller live on
each access, and tear down per-vessel pilot state on vessel destruction.
@djungelorm djungelorm added this to the 0.6.0 milestone Jul 17, 2026
@djungelorm djungelorm added bug Something isn't working service:space-center labels Jul 17, 2026
@djungelorm
djungelorm merged commit 803c8bf into main Jul 17, 2026
29 checks passed
@djungelorm
djungelorm deleted the autopilot-revert-fix branch July 17, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working service:space-center

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant