Jump to content

[SOLVED] part hierarchy and parenting


Recommended Posts

Hello everyone, I have a quick question.

I've searched the forums for a couple of hours now and I can't find the information I'm after.

Can anyone tell me what the part attachment hierarchy looks like?

I'm guessing it's something like this:

  • attachNode
    • partGameObject
      • rigidBodyGameObject
      • modelGameObject
        • model
        • colliders

But, I have no idea, and I'm not sure how to find out :o

This is what I'm trying to do:

Spoiler

I have a custom part, it resembles the rockomax hub with 6 attach nodes. In my custom part module for the hub I have defined the string name of a top level gameobject contained in the hub.mu model.
Within the OnStart method of the custom part module, I find all of the child nodes of the hub with the id of "rot", which are then added to a list<Part> variable.

So far so good, everything works. It gets tricky when I'm iterating through the  list<Part> with a foreach statement.


public void makeParent()
{
	foreach(Part childPart in childParts)
	{
		childPart.findModelTransform("model").setParent(modelTransform);
	}
}

According to the log everything is parented properly, however when I try to rotate modelTransform with modelTransform.rotate(0, 6 * TimeWarp.fixedDeltaTime,0); only the hub mesh rotates and not the child parts. I'm searching for the "model" transform because it's the parent of the first gameObject with a meshRender component, according to trial and error, although I've tried Part.partTransform, Part.gameObject.transform, and Part.transform. Allass nothing works. I'm left thinking that the problem comes down to not parenting something correctly or I have to destroy the physics joints to get this to work.

Thanks in advance,

Bonus

EDIT:

Thanks to @sarbian and Debug Stuff I was able to uncover what the basic part  hierarchy is. It looks like this:

  • Root Transform (name is the same as the part name in the cfg)
    • PartJoint
    • Other meta objects and transforms
    • Transform (named "model")
      • Transform (named "model")
      • Model.mu (this where the exported unity mu gameObjects are attached)

The problem I was having was a simple one. I assumed rigidbodies didn't interfere with the parenting of Part objects but that's not the case, because even though Part.parent is set to the parent part of the current part, it isn't literally parented. Rather, parts are glued together with the use of physics joints (configurable joints). This is accomplished through the PartJoint object, which contains a list property of configurable joints. Each configurable joint is parented to the root transform and assigned the current part's parent rigidbody as its constrained body. Rigidbodies should not be parented to each other. If you destroy the joint and then try to parent this triggers an OnDestroy event. If you try to disable the joint by setting the constrainedBody to null, the part will disconnect but not be parent-able, this might be because it's a prefab.

Parts can have bits below the "model" transform parented to things below the "model" transform in the  hierarchy easy enough though. If one tries to rotate or translate a part's Part.transform, this will result in rotating or translating the configurableJoint which will in turn apply forces to the whole vessyl. 

Edited by Bonus Eventus
Link to comment
Share on other sites

@sarbian Thanks, I'll take a look when I get off work later. 

EDIT:

Using @sarbian's Debug stuff tool and debug logging with transform.root I found out what I needed to know about the basic hierarchy. I'll update the OP with the new info.

Edited by Bonus Eventus
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...