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.
are you scaling the branches?
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 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.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
5 People are following this question.
Having difficulty with Parent Object rotation and Child Object movement.
Global rotation on child object ?
Transform.rotation is setting local rotatoin
Child lossyScale changes after setting localRotation