Jump to content

Change of active command pod


Recommended Posts

Hi

Is there something in the API I can hook into when the control module is changed using the GUI 'control from here' button? I would like to trigger some code when the active module is changed. I'm a little lost with this one, though it's possible I'm just not seeing to wood for the trees.

Many thanks, as ever.

Link to comment
Share on other sites

I'm not aware of any sort of callback event, but I've hacked together the following that works:


public NamespaceTest
{
uint lastControlPart; //what was our control part last frame? using it's FlightID

public void Update()
{
//this needs a type check, but the ReferenceTransform of the vessel is the
//reference transform of the part that gets "Control From Here". Just have to find a compare that works
if(lastControlPart!=FlightGlobals.ActiveVessel.ReferenceTransformID)
{
//put your code here that you want to run on change
lastControlPart = FlightGlobals.ActiveVessel.ReferenceTransformID;
}
}

Note that this will fire once when a vessel loads as lastControlPart will initialize as null and so this code will run once on the first update frame.

If you put a

lastControlPart = FlightGlobals.ActiveVessel.ReferenceTransformID;

in your Start(), it should avoid firing on loading the Flight Scene but I have not actually tested that.

Hope that helps,

D.

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