Attention: this question is about manually dragging objects with the mouse in the Editor, not about setting the parent through scripts!
When dragging an object in the scene hierarchy to a new parent, Unity automatically updates the local position so the world position of the dragged object remains the same.
Is there any way to prevent that? I tried holding down any combination of Ctrl / Alt / Shift while dragging, but nothing works, it always updates the local position.
Ah yes, this is how I do it:
Some background information:
You can right click its Transform component’s header in the Inspector, you’ll be able to copy the component. Later, you can then either paste a copy of that component as a new component on another GameObject (won’t work with Transforms in particular), OR you can paste the component’s values (at the time of the copy) into another Transform! This works with all components. It should look like this:
Here are the basic steps:
Before changing the GameObject’s parent, right click on the Transform’s header in the Inspector, choose “Copy Component”.
Change the parent of the GameObject. The Transform’s fields will change to the unwanted values, keeping it in the same world-space position.
Right click the GameObject’s Transform header again, now choose “Paste Component Values”. This should restore the local-space values (as seen in the Inspector)