Is there a way to move a parent object without also moving it’s children?
I don’t believe that’s possible, nor does it conceptually make much sense. After all, by definition you are a child of the parent’s transform. Detach the objects, move the former parent then reattach the objects.
The positions and rotations of the children relative to the parent can be modified via its transform’s localpositon.
You can manually re-set the child’s position after moving the parent. e.g.
temp = child.transform.position;
parent.transform.position = Vector3(10,0,0);
child.transform.position = temp;
But the above poster is right, conceptually, it doesn’t make much sense. You’re better off detaching the children before moving the parent.
Or, don’t make it a child in the first place. One alternative is to put a script on the child with a link to the object that is currently the parent. Then the child can simply follow the “parent’s” movement’s exactly, or not follow them, depending on the situation.
What if you are trying to move the mask of a UI image, which is necessarily a parent of the masked image?
- Select the Children in the Hierarchy panel:
- Move the children to outside the parent in Hierarchy panel, so they won’t be children anymore
- Move the Parent object that you want
- Move the children back, their local transform position will be managed by unity, and their original position in the world will be the same
This annoyed me too, so I made an EditorTool to fix it:
https://github.com/LaurieCheers/CheersPivotTools
Try this. Set a PositionConstraint component to the child object of the mask.
I faced this issue recently and i solved this way.
I can vouch for the CheersPivotTool EditorTool package as I just tried it out and it’s perfect.
My particular use case is that I’ve bought a few prefab assets like a grocery store where something like a door has a mesh that’s actually offset from the origin. So there’s a mesh renderer rendering a door at [200,200,0] but the transform of the door object is at [0,0,0] instead of actually being anywhere near the door.
If you try to rotate an object with a transform at [0,0,0] it rotates around the center of your world which is not what anyone would want.
My solution is to right click the door and ‘Create Empty Parent’ then use CheersPivotTools to move the new root gameobject without moving any children. This way I can line up the new root empty GameObject transform to the hinge point of the door and all rotations work exactly like they should if you rotate the new parent GameObject.