Jump to content

[Solved] Engine 'Running' in editor. How to stop?


Recommended Posts

I have a little plugin that can be applied to engines via part.cfg

MODULE
{
name = ecCoMAdjPart
maxPosError = 0.005
}

The plugin overrides OnStart

        
public override void OnStart(StartState state)
{
base.OnStart(state);
...

and implements

        
public void FixedUpdate()
{
...

It's really quite simple code and appears to work fine with one cosmetic exception: when I add a modified engine in SPH or VAB or load a craft file containing one or more modified engines they appear with fully animated exhaust/thrust tails. Once I switch to 'Flight' everything is fine and on reverting from Flight to the editor building the engines 'go out'. It looks very much like an initialisation problem.

I've looked around for examples and poked and prodded my code to no avail. What do I need to do to ensure that when an engine is added in the editor it appears without the eyeball burning animation?

Edited by ecat
Link to comment
Share on other sites

Thanks for the reply.

I don't think I modify anything to do with the stock part, I just use its position for reference and access its parent node. Also I do have a test for Editor mode, so I think I have that covered.

Here's the meat of the code. It's messy and full of debug and reveals the fact that I only know how to work in two dimensions but it will save time.

This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License

        //
// Start States
// None = 0, Editor = 1, PreLaunch = 2, Landed = 4, Docked = 8,
// Flying = 16, Splashed = 32, SubOrbital = 64, Orbital = 128
//
public override void OnStart(StartState state)
{
base.OnStart(state);

actionActivate = new KSPActionParam(0, KSPActionType.Activate);
actionDeactivate = new KSPActionParam(0, KSPActionType.Deactivate);

UnityEngine.Vector3 debugCoM = FlightGlobals.ActiveVessel.localCoM;
Vector3 coMOffset = this.part.CoMOffset; // orgPos;

// maxPosError = 0.005f;
Debug.Log("ecCoMAdj maxPosError " + maxPosError);
// trackCoM = false;

currentMovement = 0;

// GUICoMTrkOff();

SetGUICoMTrkEvents();

Debug.Log("ecCoMAdj StartState " + (int)state );

if (state != StartState.None && state != StartState.Editor)
{
Debug.Log("ecCoMAdj Starting Part data1 P() R() (" + this.part.orgPos.x + ", " + this.part.orgPos.y + ", " + this.part.orgPos.z + ") (" + this.part.orgRot.x + ", " + this.part.orgRot.y + ", " + this.part.orgRot.z +
")");

Debug.Log("ecCoMAdj Starting CoM data1 V() P() (" + debugCoM.x + ", " + debugCoM.y + ", " + debugCoM.z + ") (" + coMOffset.x + ", " + coMOffset.y + ", " + coMOffset.z +
")");

debugCoM = FlightGlobals.ActiveVessel.localCoM;
Vector3 coMOffset2 = this.part.orgPos;

Debug.Log("ecCoMAdj Starting CoM data2 V() P() (" + debugCoM.x + ", " + debugCoM.y + ", " + debugCoM.z + ") (" + coMOffset2.x + ", " + coMOffset2.y + ", " + coMOffset2.z +
")");

Debug.Log("ecCoMAdj Starting Parent partName, ClassName " + this.part.parent.partName + ", " + this.part.parent.ClassName);
Debug.Log("ecCoMAdj Starting Parent Q rotation (" + this.part.parent.orgRot.x + ", " + this.part.parent.orgRot.y + ", " + this.part.parent.orgRot.z + ")");
Debug.Log("ecCoMAdj Starting Parent E rotation (" + this.part.parent.orgRot.eulerAngles.x + ", " + this.part.parent.orgRot.eulerAngles.y + ", " + this.part.parent.orgRot.eulerAngles.z + ")");


}



Edit:

I've just noticed that when the engine is first added as mentioned above, it does have the thrust animation but it does not have an engine staging icon! The icon appears correctly in Flight and after a Revert.

Edited by ecat
Link to comment
Share on other sites

heh!

The reason I couldn't find any glaring errors when compared to the code used in B9 etc is that there are no glaring errors... Apart from one...


UnityEngine.Vector3 debugCoM = FlightGlobals.ActiveVessel.localCoM;

ActiveVessel is not valid first time through the editor so the code failed to complete which for some reason broke the default engine initialisation.

After the first flight all appeared well.

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