Jump to content

Autopilot/FlyByWire callback getting wrong values from properties/fields


Nelluq

Recommended Posts

I made an account to post this because I've used up all my debugging ability and can't for the life of me figure out what's going on.

I'm writing a mod that needs to get data from the vessel and control it. This is all being done from a PartModule subclass:

class Controller : PartModule {
  public bool Running { get; private set; }
  
  public override void OnStartFinished(StartState state) {
    if (state != StartState.Editor) {
      vessel.OnAutopilotUpdate += FlyByWireHandler;  // also tried with vessel.OnFlyByWire, same result
    }
  }
  
  public override void OnFixedUpdate() {
    Debug.Log("OnFixedUpdate Running="+Running);
    if (Running) {
      // get data from the vessel
    }
  }
  
  private void FlyByWireHandler(FlightCtrlState state) {
    Debug.Log("FlyByWireHandler Running="+Running);
    if (Running) {
      // control vessel
    }
  }
  
  public void Start() {
    Running = true;
  }
  
  public void Stop() {
    Running = false;
  }
}

There's normally some other stuff in there too, but I've gone so far as to strip it back to just this and the problem still happens.

As expected, both OnFixedUpdate and FlyByWireHandler get called on every physics update, and dump logs to the debug console. After Start() has been run (it gets called by a separate UI object), the logs from OnFixedUpdate() turn into "OnFixedUpdate Running=True", as expected, but the logs from FlyByWireHandler() remain as "FlyByWireHandler Running=False", and no code within the if statement runs. I've been stuck here for 2 whole days, and I just can't figure out why the same property would be read as true by one method and false by another. I've tried making Running a public field (public bool Running; instead of public bool Running {get; private set}), and that doesn't change anything (not that I expected it to).

Does anyone know why this might be happening, or at least anything else I can try to narrow down the issue? This behavior makes absolutely no sense to me.

Link to comment
Share on other sites

  • 2 weeks later...
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...