Jump to content

ModuleDecoupler woes


Recommended Posts

I am trying to add a ModuleDecouple to a part programmatically to a part.  It's not working, but I don't know why.

This is a new part module I'm writing, which will add a ModuleDecouple at edit time based on the user's input.

What I'm doing is adding the ModuleDecouple component to the part gameObject, and then adding the new module the the part.Modules.

It appears to work, but staging isn't updated, and when I trigger it in flight, I hear the decoupling sound but nothing happens.

Suggestions are welcome (obviously).

The code I'm using follows.  It is probably trying to do too much, but I've been trying everything I can find:

decouplerModule = this.part.gameObject.AddComponent<ModuleDecouple>();
 
this.part.Modules.Add(decouplerModule);
decouplerModule.enabled = true;

decouplerModule.ejectionForce = ejectionForce;
decouplerModule.explosiveNodeID = explosiveNodeID;

decouplerModule.overrideStagingIconIfBlank = true;
decouplerModule.stagingToggleEnabledEditor = true;
decouplerModule.staged = true;

decouplerModule.SetStaging(true);

decouplerModule.UpdateStagingToggle();
  
decouplerModule.stagingEnabled = true;

this.part.UpdateStageability(true, true);
  

 

Edited by linuxgurugamer
Link to comment
Share on other sites

I dunno if this helps but I was just having issues with dynamically creating a different component.

1. I had to create the component in the partmodule's OnStart event.  If I tried to create it during the OnActivate I could see it created the component but I couldn't interact with it (open a PAW). 

2. Adding it to the OnStart created another problem when copying the parent part (symmetry turned on).  OnStart appears to run whenever you select a part and when it copies one for symmetry. It would copy the parent part and it copied the created component perfectly but it would add 2 copies of the component to the duplicate part. When opening the PAW, only the second one could be interacted with.  I attempted to check and see if that component already existed before creating it in the OnStart and that prevented the second copy but I couldn't interact with the one that was created in OnCopy and I got a nullRef trying to open the PAW even though, I could see the component.  I had to end up looking for the component by it's type and destroying it in the OnCopy event.  Then, have the OnStart check to see if the component existed (null) and create a new one if it  didn't.

Ya, mindboggling... GL.

 

Link to comment
Share on other sites

Weird! My issue is that I have the first part module which has a PAW, in the editor, which, when you click, creates the module decoupler. So, I guess that would run in the on GUI event, maybe I need to change that to set a flag and then run during the update. At least it's something to try. Thank you

Link to comment
Share on other sites

51 minutes ago, linuxgurugamer said:

Weird! My issue is that I have the first part module which has a PAW, in the editor, which, when you click, creates the module decoupler. So, I guess that would run in the on GUI event, maybe I need to change that to set a flag and then run during the update. At least it's something to try. Thank you

Initially I had mine like that. Which brings up another thot.  Took me a bit to get mine turned and rotated in the right direction.  I've never worked with a decoupler but I have worked with the Klaw.  Getting the rotation right for it was a bit tricky.  Does rotation and position affect the decoupler?  I notice you're just sorta dropping it in.

Edited by Fengist
Link to comment
Share on other sites

3 hours ago, Fengist said:

Initially I had mine like that. Which brings up another thot.  Took me a bit to get mine turned and rotated in the right direction.  I've never worked with a decoupler but I have worked with the Klaw.  Getting the rotation right for it was a bit tricky.  Does rotation and position affect the decoupler?  I notice you're just sorta dropping it in.

The decoupler references a node, which is known.  I'm not creating a part, just adding a part module

Edited by linuxgurugamer
Link to comment
Share on other sites

3 minutes ago, Fengist said:

Got it.  For some reason I was thinking a transform was involved.

In a future version I'd like to be able to add a number of separtrons to the top of the tank, and then I'll have this problem.  But for now, I just want to have the module functioning properly

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