- Home /
Relative transforms and parenting
I have logic that creates a tree like structure - branches grow out of a root position. Initially I set it up so that each branch is separate (let's assume cylinders for now). I would like to parent them so that each subsequent sub-branch is parented to the one before it. However, when I set the parent - the transformations get messed up. How can I ensure that the position, rotation and scale of the sub-branch remains the same (like it was when there was no parent). I have tried SetParent(parent, false) but that doesn't work.
The unfortunate answer is that your objects likely aren't a size scale of 1:1:1, to resolve this, you will need to place each branch in an empty gameobject that is a scale of 1:1:1.
Thanks Rob ! That's exactly what I did to work around this
Answer by supernova2014 · Mar 20, 2017 at 05:51 AM
yes - the branches are scaled and parented to scaled geometry. I tried adding an empty game object in the hierarchy between the scaled parent and child branch, but that doesn't seem to be working either...
I figured out a work around - basically Unity messes up whenever you parent anything to a scaled object. So I added empty objects that parent to other empty objects and grouped together related objects under these objects. This way the parented heirarchy is all empty transforms.
that would have been my suggesting, too.