Jump to content

Events for docking and undocking


Recommended Posts

I'm looking for events that a VesselModule can subscribe to so it knows when its vessel has docked with or undocked from another vessel - specifically, an event like "Vessel X is docking with Vessel Y" or "Vessel X is a new vessel because it undocked from Vessel Y".  It looks like the SameVesselDocked and SameVesselUndocked callbacks in GameEvents would do the trick, but I don't see them firing.

What I'm trying to accomplish is this: In RasterPropMonitor, I've got a dictionary of "persistent" variables that primarily track the state of various values consumed by props in a craft.  When I dock, I'd like the VesselModules involved in docking to collate their values together, so that the new, combined vessel has all the persistents from the two separate craft.  Likewise, when I undock, I'd like the newly-created craft to inherit the entire contents of the persistent variables dictionary.

Based on the parameters for the SameVessel* events, those looked like they'd do the trick, but, like I said, I don't see them firing.  Is there some other way I can know when two craft are combining, or when a new craft exists because it separated from another craft?

Link to comment
Share on other sites

OnPartCouple is used for docking. It gives a From and a To Part (the docking ports) and fires before the vessels are actually joined. The From vessel is not necessarily the active vessel, I think it is the dominant docking port, which is determined by other things.

I think OnVesselCreate is the one used when undocking (and maybe decoupling, too).

I think the SameVesselDocked/Undocked are used when two ports on the same vessel join together, not regular docking.

Edited by DMagic
Link to comment
Share on other sites

Just now, DMagic said:

OnPartCouple is used for docking. It gives a From and a To Part (the docking ports) and fires before the vessels are actually joined.

I think OnVesselCreate is the one used when undocking (and maybe decoupling, too)

Not near my PC right now, but that sounds about right for the ones I use.

Link to comment
Share on other sites

13 minutes ago, DMagic said:

OnPartCouple is used for docking. It gives a From and a To Part (the docking ports) and fires before the vessels are actually joined. The From vessel is not necessarily the active vessel, I think it is the dominant docking port, which is determined by other things.

I think OnVesselCreate is the one used when undocking (and maybe decoupling, too).

I think the SameVesselDocked/Undocked are used when two ports on the same vessel join together, not regular docking.

Hmm.  So there's not a clear way to tell who spawned a vessel when undocking?  I can look at the OnVesselWasModified sequence and hack something together with that, I suppose.

Thanks for pointing me at OnPartCouple.

Link to comment
Share on other sites

1 hour ago, DMagic said:

Well, there is an OnPartUndock event, I haven't really looked at it, but it sounds promising. I'm not sure if it gets fired from both vessels or only the vessel with the active port.

That last time I enabled that one, I never saw it fire, either.  Although I don't remember when it was that I tried it last.  Guess I'll have to go poke at it some more.

Link to comment
Share on other sites

Okay, here's what I found: OnPartCouple works as advertised, so I can collate databases upon docking easily.

Undocking is trickier:

onPartUndock fires, containing the part that undocked (this is seen by the old Vessel Module, or OVM).

The new vessel is created and the new craft's VesselModule wakes up (I'll call it NVM for New Vessel Module).

After that, I see vessel modified callbacks: both OVM and NVM see onVesselModified for the new vessel.  Then, OnSave happens for the new vessel.  And, finally, I see vessel modified callbacks for the old vessel.

I don't know what the criteria are for onVesselModified (that is, which VesselModules will see them, and what triggers them), so I don't think I want to merge values every time I see that callback, but maybe I can add some code to remember when a vessel sees the "Undock" message, and use that knowledge to assume that the next VesselModified callback it sees refers to the newly-created undocked ship.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...