Jump to content

How to detect docking has occured on active vessel


Recommended Posts

I used to think that OnStart was called after docking, but this turned out to be incorrect.

Now the question is, how to detect, docking has occurred with another vessel?

I need it in order to reinitialize some vessel specific variables.

Edited by FreeThinker
Link to comment
Share on other sites

It's not a method, it's a static EventData object, found in the GameEvents class. Simply call GameEvents.onVesselDocked.Add(method) to subscribe to it, and GameEvents.onVesselDocked.Remove(method) to unsubscribe.

Example:


[KSPAddon(KSPAddon.Startup.Flight, false)]
public class GameEventSubscriber : MonoBehaviour
{
void Start()
{
GameEvents.onHideUI.Add (OnHideUI);
}
void OnDestroy()
{
//this part is important too!
GameEvents.onHideUI.Remove(OnHideUI);
}


void OnHideUI()
{
Debug.Log("OnHideUI");
}
}

Unsubscribing, by calling event.Remove is important, becausde if you don't then the same method could build up, and you'd have many calls of the same method for the same event.

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...