Jump to content

How to update the orbit of a (about to be unloaded) vessel?


Recommended Posts

I'm attempting to alter the orbit of a vessel as it is unloaded (and therefore cannot be further influenced by the player). I've hooked GameEvents.onVesselDestroy and my method seems to be called for all the right vessels at all the right times (I'm only altering orbits for which vessel.loaded is true).

The problem is, nothing happens.

After failing several times, I looked at the code HyperEdit uses to alter orbits. I'm doing (mostly) the same thing:

vessel.orbitDriver.orbit.inclination = 0;

vessel.orbitDriver.orbit.Init();

vessel.orbitDriver.orbit.UpdateFromUT(Planetarium.GetUniversalTime());

But nothing happens. When my vessel is saved to the persistent.sfs file, the orbit's eccentricity has not changed. The only thing I can see that I'm doing differently than HyperEdit is that I'm not calling OrbitPhysicsManager.HoldVesselUnpack(60) and forcing all the vessels onto rails. If I try to do this, I get an NRE:

[EXC 08:32:27.981] NullReferenceException

UnityEngine.Component.SendMessage (System.String methodName, SendMessageOptions options)

Part.Pack ()

Vessel.GoOnRails ()

Any ideas? How do I update the orbit of a vessel after the player has switched away from it?

Link to comment
Share on other sites

As an update, I've tried waiting until the vessel is unloaded (vessel.loaded is false), and I'm still unable to alter the orbit. Is there no way to alter the orbit of a vessel that is not currently being flown?

From what I can tell, I'm doing *exactly* what HyperEdit is doing in the "align SMAs" tool.

Edited by godefroi
Link to comment
Share on other sites

might be unpractical, but have you tried to "load" the vessel before you update the orbit?

it'll be loaded for one frame only.. but that should be enough..

correct me if I'm wrong, but if vessels are unloaded, the orbit data is no longer "active" - you can't call functions on them.

that works only if the vessels are loaded.. - at least afaik

not suggested to loop through hundreds of vessels and load them all though..

for one vessel it should work in my book..

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