Jump to content

Prevent part from becoming root


Recommended Posts

Hi,

is it possible to prevent that a part becomes root? Be it with a certain setting in the config file or (more likely) with a certain code snippet in a PartModule?

I know that parts that are physicsless or don't have a stack node can't become root, but the part I need, does have stack nodes and is too big (and heavy) to be physicsless.

So, is it possible to do this via code? 

Link to comment
Share on other sites

@sarbian Thanks for the answer. Well, then i have to live with that.

I must have a look at the API, maybe a PartModule can cause the vessel to change its root when it detects that the part it belongs to is/has become root. But i'm afraid this will have unforseen consequences if at all possible. 

Edited by Nils277
Link to comment
Share on other sites

I think there is a way to achieve what i want.

It's not that obvious but there is this member in the AttachRules of the part:

part.attachRules.allowRoot

at least this does seem to prevent the part from becoming root in the VAB/SPH. Still need to verify this in flight though...(especially when two vessels undock and one of the docking ports can become the root of the new vessel)

Edit: Looking even further i found that this can also be done with the 8th paramter of the attachRules field in the config of a part. 

Edited by Nils277
Link to comment
Share on other sites

Although i feel bad about triple posting, here's what I found out:

  1. It is possible to prevent a part from becoming root in the editor by either using the 8.th flag of the AttachRules or making the part physicsless.
  2. Both being physicsless or having the 8.th flag set to 0 does NOT prevent a part from becoming the root in flight. Tested it with a docking port
  3. Making a docking port physicsless causes it to spam NREs when attempting to dock.
  4. All my attempts to change the root of a vessel caused strange physical behaviour. (Vessel seems to be nearly weightless and always tips over to the same side)

If someone knows how to change the root in flight (or has an idea), please let me know. 

 

Link to comment
Share on other sites

While I'm not sure I can actually help, I'm pretty sure that everything you are seeing comes from the fact that the root part is the "start" of the vessel layout in the data file.

So I presume that when you change the root in flight, there is no more "start point" for building the vessel and while it may render on-screen, a whole bunch of behind the scenes stuff has gone wrong.

Now, Squad obviously has code buried in the game somewhere to handle the changing of root parts, at the very least undocking would require this. If you can hook into that you are good to go, otherwise I'd look at trying to resolve your issue another way.

Trying to reverse engineer everything that goes on and change the root part yourself is just asking to summon the kraken if you miss the tiniest thing. It would also be very prone to breaking any time KSP updated.

D.

Edited by Diazo
Link to comment
Share on other sites

You are right, changing the root of a vessel by hand is really prone to cause many errors and i have not yet found any public function in the API that does this automatically, so i may be out of luck. 

Edited by Nils277
Link to comment
Share on other sites

On 15/1/2017 at 5:54 PM, Nils277 said:

part.attachRules.allowRoot

On 15/1/2017 at 5:54 PM, Nils277 said:

Looking even further i found that this can also be done with the 8th paramter of the attachRules field in the config of a part. 

Could you please provide an example on how the attachRules look with allowRoot is negative/positive?

 

 

Link to comment
Share on other sites

55 minutes ago, Warezcrawler said:

Could you please provide an example on how the attachRules look with allowRoot is negative/positive?

In the config file:

When the part is allowed to be root:

attachRules = 1,0,1,1,0,1,1,1

when the part should not be root:

attachRules = 1,0,1,1,0,1,1,0

The first five paramters are the well known ones. 
The 6.th and 7.th are allowDock and allowRotate. They are 1 by default, i have left them that way and did not test what they do.
The 8.th parameter is allowRoot. It defaults to 1 where the part is allowed to be root and 0 when it is not allowed.

 

Alternatively in plugin code (in a PartModule)

Part is not allowed to be root:

part.attachRules.allowRoot = false;

or part is not allowed to be root

part.attachRules.allowRoot = true;

 

Edited by Nils277
Link to comment
Share on other sites

31 minutes ago, sarbian said:

And as stated earlier in the thread this is only true in the editor.

Thanks for pointing that out... I had missed that one info in the thread :kiss:

I was hoping this could help prevent some root problems with docking/undocking.

Edited by Warezcrawler
Link to comment
Share on other sites

1 minute ago, Warezcrawler said:

Thanks for pointing the out... I had missed that one info in the thread :kiss:

I was hoping this could help prevent some root problems with docking/undocking.

Unfortunately not...and that is exactly my problem. The partModule i'm writing strictly needs a parent part and would ideally also have a docking port...but undocking causes exactly this part to very often become root.

Link to comment
Share on other sites

Just now, Nils277 said:

Unfortunately not...and that is exactly my problem. The partModule i'm writing strictly needs a parent part and would ideally also have a docking port...but undocking causes exactly this part to very often become root.

Yeah.... I see your point... The karbonite generator (KEG-2500 Karbelectric Generator) really messes things up if it becomes root. It becomes invisible, and physics can misbehave - this was at least a problem back in 1.1 :/

Docking ports themselves could probably use a prevention of root. Maybe this is actually the problem "Infernal Robotics" had, where combining docking ports and IR was not something you should do....

Link to comment
Share on other sites

Yes, IR needs a parent part for the Joints to work. Also when two ships dock it is possible that the parent part changes, which completely destroys all saved translations and rotations because they are relative to the original parent.

It would be really great when a part that is set to not be the root part in the editor will also not become root in flight. I mean the flag was set for a valid reason and will most likely only affect the vessel in flight and not in the editor

Edited by Nils277
Link to comment
Share on other sites

14 minutes ago, Nils277 said:

Yes, IR needs a parent part for the Joints to work. Also when two ships dock it is possible that the parent part changes, which completely destroys all saved translations and rotations because they are relative to the original parent.

It would be really great when a part that is set to not be the root part in the editor will also not become root in flight. I mean the flag was set for a valid reason and will most likely only affect the vessel in flight and not in the editor

Yes.. That, or another setting, like the ninth one, that would set the inflight allowroot setting... Maybe if a request is passed to squad they might incorporate that?!

Link to comment
Share on other sites

  • 4 weeks later...
On 1/15/2017 at 11:54 AM, Nils277 said:

I think there is a way to achieve what i want.

It's not that obvious but there is this member in the AttachRules of the part:


part.attachRules.allowRoot

at least this does seem to prevent the part from becoming root in the VAB/SPH. Still need to verify this in flight though...(especially when two vessels undock and one of the docking ports can become the root of the new vessel)

Edit: Looking even further i found that this can also be done with the 8th paramter of the attachRules field in the config of a part. 

Just tried this, it seems that some other modules will override this (probably ModuleCommand, among others)

I ended up using the attachRules as you described in the part

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