Jump to content

Can I get a definitive answer for the *un*dock event in KSP 1.04?


Recommended Posts

Hi. I'm SixHourDays, and I'm a few months into my first plugin. This forum has been a goldmine of answers for SO MUCH of what I needed. So thank you!

I'm looking for the specific GameEvents event for undocking.

ANSWERED: onPartUndock fires for all undocking, except the first undock of something attached to them in VAB (including another docking port). Subsequent undockings of these ports will fire onPartUndock like usual.

onPartJointBreak will fire for all undockings, even the aforementioned special case, on every try.

------------

The onPartUndock and onUndock events don't fire for me.


//inside my plugin's Awake()
GameEvents.onPartCouple.Add( MyDockEventHandler ); //this works fine for docking
GameEvents.???.Add( MyUndockEventHandler ); //what do I subscribe my handler to?

For the curious, I am unsubscribing from these same handlers in OnDestroy. Even more peculiar is most other events work. I readily get events for OnPartDie, OnExperimentDeployed, OnCrewTransferred, OnStageSeparate, etc.

From the assembly info on GameEvents.cs, I see only these that I could use...


public static EventData<Part> onPartUndock; //tried it, didn't fire
public static EventData<GameEvents.FromToAction<ModuleDockingNode, ModuleDockingNode>> onSameVesselDock; //wrong (docking), and I want the two ship case
public static EventData<GameEvents.FromToAction<ModuleDockingNode, ModuleDockingNode>> onSameVesselUndock; //I want the two ship case
public static EventData<EventReport> onUndock; //tried it, didn't fire

Thanks for anyone's help in this.

Edited by SixHourDays
Link to comment
Share on other sites

I have looked for this myself but was also unable to find one. The closest I found was an event that fired when a part's connection to another part was deleted. But as this included such things as crashes, explosions, etc. and so it didn't work for me.

I thought that was the onPartUndock event, but you say you've checked it so I'm not sure what's happening there. (I'm also going back to the KSP 0.90 days here, maybe something changed.)

Now, it sounds like you need the actual Undock event for what you are doing so my this probably won't work for you, but my workaround was to monitor the Vessel.rootPart and Vessel.parts.count properties and trigger my code when either of those things changed. Note this triggers a lot more often then on just undocking.

D.

Edited by Diazo
Link to comment
Share on other sites

Update!

Here's a pic of the test ship

I've registered for these events:

GameEvents.onVesselWasModified.Add(OnVesselModified);
GameEvents.onPartCouple.Add(OnPartCouple);
GameEvents.onPartUndock.Add(OnPartUndock);
GameEvents.onSameVesselDock.Add(OnSameVesselDock);
GameEvents.onSameVesselUndock.Add(OnSameVesselUndock);
GameEvents.onUndock.Add(OnUndock);

I've discovered the following sequence of events occur:

Undock the capsules:

- OnVesselModified event x2

Redock the capsules:

- OnPartCouple event

- OnVesselModified event x2

Undock capsules
again:

- OnPartUndock event

- OnVesselModified event x2

Redock the capsules
again
:

- OnPartCouple event

- OnVesselModified event x2

So, why doesn't OnPartUndock or OnSameVesselUndock fire during the first undock event? Why only on 2nd docking forward? I'm betting something about launching the ship with the two capsules docked counts as it all being one ship, until I split it with the first undock. But then I'd expect OnSameVesselUndock to cover that case...

As always, any help is appreciated.

Edited by SixHourDays
Link to comment
Share on other sites

How are you undocking the first time? It doesn't fire when you use the decouple option from the docking port. Or, it might be as you said, that it doesn't count for parts "docked" together in the VAB.

You can use onVesselCreate if you want something that works every time. Of course, it also gets called for lots of other things.

But any undock or decouple event triggers it; you would just have to do lots of checking to make sure that the event is triggered by the vessel you are looking for.

Link to comment
Share on other sites

I'm guessing that when you place two docking ports together in the editor, they don't count as docked to start with. Notice that the event is called "decouple" rather than "undock" the first time. It's probably behaving like a decoupler in this case.

Link to comment
Share on other sites

How are you undocking the first time? It doesn't fire when you use the decouple option from the docking port.

The only way I know of undocking is to right click the docking port, and select "Decouple Node" (or use an action group). Is there another way I'm oblivious to? If you mean code-undocking, that's not what I'm doing. This is all meant to capture normal-user-gameplay undocks.

I'm guessing that when you place two docking ports together in the editor, they don't count as docked to start with.

I agree with you, it seems that the VAB created docked ports behave different.

Notice that the event is called "decouple" rather than "undock" the first time. It's probably behaving like a decoupler in this case.

The only GameEvent with "couple" anywhere in the name is

public static EventData<GameEvents.FromToAction<Part, Part>> onPartCouple;

which I have subscribed to, and am listening for. It fires during docking/redocking.

I don't see a 'decouple' event anywhere in GameEvents.cs.

Does anyone understand the nature of docking ports which were built docked to one another in VAB?

Link to comment
Share on other sites

I can tell you that onStageSeparation does not fire, and that onVesselWasModified does fire.

When I get home I'll try out onPartJointBreak, and onVesselCreate. Can I ask what the 'normal' intention of onPartJoinBreak is? Struts snapping, parts cracking off others?

Regardless, thanks for the suggestion :-)

Link to comment
Share on other sites

A side thought: in the VAB, you can attach any part to a docking port, and then undocking in game is a one way trip, releasing that stack permanently, and exposing the docking port for normal use. I wonder if that's the reasoning for this: easier to assume anything attached to the docking port is just a normal part being discarded, even if that part happens to be another docking port, appearing to be docked.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...