Jump to content

Dock/undock event?


Recommended Posts

Is there someway to detect if a docking/undocking has been performed?

I'd like to check if one of my parts was docked/undocked to another one of my parts. I've checked the "current" KSP API, and can't find it, so, if it doesn't exist, what would be a nice workaround?

Link to comment
Share on other sites

Lets try a slightly different question, but it would still meet my requirements...

Is it possible to somehow check if a part is still part of the current vessel, without having to loop over all the parts again? I really want to avoid loops if at all possible...

Link to comment
Share on other sites

There's an OnUndock event in GameEvents but there doesn't seem to be a corresponding dock event, I'm not sure what's fired solely on docking, although there are events like OnActive that are fired on docking as well as elsewhere.

Link to comment
Share on other sites

You could hide the Couple method by replacing it with your own. This is bad design (the dispatches are not uniform), but it should work as long as you only execute the extra code in the situation you need it.. (e.g. both parts are what you desire).


public class YourPlugin : DockingPort
{
public new void Couple(Part tgtPart)
{
base.Couple(tgtPart); // <- Do not remove.

// Your code.
}

//public new void decouple(float breakForce) calls:
protected override void onDecouple(float breakForce)
{
//base.onDecouple(breakForce); // <- Safe to remove.

// Your code.
}
}

Once again, just keep in mind that the method wasn't designed to be overridden - your best solution at this moment would be to co-routine an enumerator to solve the situation (imo).

Edited by Razchek
Link to comment
Share on other sites

Does anyone know if the pointer to a part remains valid if the part is no longer a part of the current vessel? This would seem to be the easiest way to check for a parts existance.

Link to comment
Share on other sites

onDecouple is called before the OnUndock GameEvent is.

--

While onDecouple is being executed the part is still connected and the attachJoint still remains.

With the OnUndock callback the above is not true and the part is no longer in the original vessel hierarchy.

Edited by Razchek
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...