Hi Guys,
I’m having some pretty heavy confusion over how exactly parenting works in relation to position/rotation/scale. I discovered pretty early that depending on how you attach a GameObject to another changes how it’s own transform is affected. From what I see there’s 4 ways to attach a GameObject. All with different effects:
- Drag and Drop a GameObject onto Another - When you do this the object will stay in the same position as it was in the world, however it’s localPosition, localScale, and localRotation will change to keep that object in the same position. All parent movements and transform changes affect the child.
- Set Parent by Calling in Script ‘transform.parent = someObject.transform’ - When you do this, the object’s localScale, localRotation, and localPosition will stay the same relative to the parent. However that means the world position will change. It looks like the object teleports into a strange position and rotation, and possibly skew, depending on the parent’s transform.
- Set Parent by Calling ‘transform.SetParent(someTransform, false)’ - This will keep the same world position, like dragging and dropping. However it bears no semblance to the first option, in the sense that when the parent is transformed in any way, the child will not follow suit. Ever.
- Set Parent by Calling ‘transform.SetParent(someTransform, true)’ - Exactly the same as 2.
I just need to check that this is correct. Secondly. Supposing you want to do the equivalent of the first one; dragging and dropping the GameObject. Where the real world position/rotation/scale is kept the same, however the child’s relative local position/scale/rotation changes. Allowing the parent’s transform to still affect the child. I’ve noticed by doing transform.SetParent() does not perform this task.
People’s thoughts on this?
I want to have a number of transform options, moving forward with Unity projects. For example it’d be good to allow a specific aspect of a parent’s transform to affect the child. Like only the position, or only the rotation, or the scale. Alternately, to allow the parenting to keep the same world position for the child, changing the relative local’s of the child according to the parent’s transform, WHILE allowing the object to follow the parent’s transform changes from then on. Does anyone have any advice on how to change this?