Jump to content

Deactivating a part when vessel destroyed


Recommended Posts

And by vessel destroyed, I mean it's no longer part of a controllable vessel, (forcibly) removed from said vessel, suffered unscheduled disassembly or otherwise classed as debris.

My parts keep on running, including sound effects, so I need a way of stopping or disabling the partmodule in such circumstances. Any ideas? I had assumed this would happen automatically, but apparently not!

Cheers :)

Edited by lo-fi
Link to comment
Share on other sites

There should be a game event of some sort you could tie into, but I as I don't know that event, I would probably use something like the following.

In your partModule code:


Vessel lastVessel;

public void FixedUpdate()
{
if(lastVessel != this.part.vessel) //this statement checks to see if the vessel this partModule is attached to belongs to the same vessel it did last FixedUpdate frame
{
--Insert your code to check if the partModule should be active or not.
lastVessel = this.part.vessel; //Set our lastVessel variable so that on the next FixedUpdate frame the if statement above is false and does not execute.
}
}

Hope that helps some,

D.

Edited by Diazo
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...