Jump to content

Event for "vessel launched"? Nothing seems quite right.


Recommended Posts

I'm trying to figure out how to get an event that fires when a new vessel is launched, and only that.  That is, it fires once, when the new vessel shows up on the launchpad.  There are a whole lot of GameEvents that seem like they ought to fit the bill, only none of them quite seem to do what I need, and I haven't figured out how to make this work:

  • GameEvents.OnVesselRollout:  Seems perfect... except that it gives me a ShipConstruct instead of a Vessel, which is useless to me.  I need the vessel.
  • GameEvents.onVesselCreate:  This gets called when launching a new vessel... but also at other times, too, such as undocking.  I could add a check for "is its situation PRELAUNCH", but that is buggy.  I launch a new ship, it fires.  I switch to another ship.  I come back to the original ship (which is still in prelaunch), and it fires a second time, which is a problem.
  • GameEvents.onVesselChange:  Same problem as with onVesselCreate.

I suppose I could try to hack something, like creating a VesselModule just to hold a boolean and nothing else, which is initialized to false at construction time, and set to "true" the first time the event fires, so that the vessel's history can be remembered... but gosh that seems clunky.

Any suggestions as to how to uniquely identify only the case where a vessel has just been launched, on the launchpad, for the very first time?

Link to comment
Share on other sites

Try GameEvents.OnLaunch.  I believe that was the one I used once upon a time.

EDIT: Actually that one might not return a vessel.  I don't think in my case I had needed it.

Edited by Alshain
Link to comment
Share on other sites

48 minutes ago, Alshain said:

Try GameEvents.OnLaunch.  I believe that was the one I used once upon a time.

EDIT: Actually that one might not return a vessel.  I don't think in my case I had needed it.

Yeah, that one doesn't have a vessel.  It's weird.  The documentation wiki I usually use (which I believe was programmatically generated in some fashion) is here:

http://docuwiki-kspapi.rhcloud.com/#/classes/GameEvents

...and it documents onLaunch as being of type EventData<Vessel>, which would be perfect.

Except when I go and try to actually use onLaunch, it turns out that the actual type of this event (i.e. from KSP's Assembly-CSharp) is of type "EventReport", which has various parameters on it including a part (not vessel) that is the origin of the event.  Also, I tried registering for it just now, and it doesn't appear to fire at all when launching a vessel, so I have no idea what onLaunch actually does (or even whether the word "launch" means as in "on the launchpad" or as in "launching a program" or something).

In any case, alas, it appears that onLaunch is not it.

Link to comment
Share on other sites

Just now, Benjamin Kerman said:

What if you checked the vessel's MET? When you have GameEvents.OnLaunch, you can look at all vessels with MET under 10 seconds, and then get the vessel from that. 

But MET doesn't start until it leaves the prelaunch state (iirc) and Snark said "I come back to the original ship (which is still in prelaunch), and it fires a second time, which is a problem."

Link to comment
Share on other sites

3 minutes ago, TheRagingIrishman said:

But MET doesn't start until it leaves the prelaunch state (iirc) and Snark said "I come back to the original ship (which is still in prelaunch), and it fires a second time, which is a problem."

Hmm. This is a tricky nut to crack. I'll take a look, report back later if i find anything, 

Link to comment
Share on other sites

18 hours ago, Snark said:

Yeah, that one doesn't have a vessel.  It's weird.  The documentation wiki I usually use (which I believe was programmatically generated in some fashion) is here:

http://docuwiki-kspapi.rhcloud.com/#/classes/GameEvents

...and it documents onLaunch as being of type EventData<Vessel>, which would be perfect.

Except when I go and try to actually use onLaunch, it turns out that the actual type of this event (i.e. from KSP's Assembly-CSharp) is of type "EventReport", which has various parameters on it including a part (not vessel) that is the origin of the event.  Also, I tried registering for it just now, and it doesn't appear to fire at all when launching a vessel, so I have no idea what onLaunch actually does (or even whether the word "launch" means as in "on the launchpad" or as in "launching a program" or something).

In any case, alas, it appears that onLaunch is not it.

This one is from Squad and programmatically generated from comments in the code. (EDIT: That is to say, what little documentation there is, AFAIK Doxygen only uses comments in the XML Documentation standard, standard // and /* */ comments can't be seen.)

https://kerbalspaceprogram.com/api/index.html

The one you are using is generated from code but community documented and as such may be erroneous.

Edited by Alshain
Link to comment
Share on other sites

If OnVesselRollout fires only when a new vessel is launched, and only then, then maybe you can just find the active vessel as soon as the event fires. You could do some additional checks, like matching the name of the vessel to the name of the ship construct, checking the vessel situation, etc...

ShipConstruct also has a list of the parts on the vessel, so maybe you can check those for their vessel reference. Though maybe that hasn't been set by the time the event is fired (the same could be true for the active vessel reference). You could always use a coroutine to wait a frame or two if that is the case.

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