How to transform only a parent and not its children?

How would i do this?

Children always move with their parent, but you can compensate for that.

Here’s some JS code to demonstrate the rough idea:

//example movement vector
var movement = Vector3.one;

//move whatever object this script is attached to
transform.position += movement;

//apply equal and opposite movement to each child
for (var child : Transform in transform) {
    child.position -= movement;
}

I’d like to add a request for this possibility (transform / move parents but not the children).
And although you normaly indeed parent objects because they should be grouped and transformed together, this is not always intended - and not related to bad design, thus I wouldnt agree to @BoredMormon and @RedHedZed here.

Here is my usecase:
I am using the (commonly used) “Floating Origin” technique for my space game.
So, I generally keep my camera close to the origin (0,0,0) for precision reasons. When the camera has moved to a certain distance, I reset the camera to the origin (0,0,0) and move all objects around for the same distance → Floating Origin.

In that case I have to move a lot of object at once. Extreme situations where I have to move everything each frame is not unlikely. Thus a highly optimized strategy is required for performance reasons.

The way I do it now is to traverse through the children of an object (which is an empty “Space”-Object) and move each object individually by the same distance. The corresponding script (which realized Floating Origin) is attached to the camera:

[RequireComponent(typeof(Camera))]
public class FloatingOriginByParent : MonoBehaviour
{
    public float threshold = 6000.0f;
    public GameObject parentGameObject; // GameObject where all child objects are to be shifted
    void LateUpdate()
    {
        Vector3 cameraPosition = gameObject.transform.position;

        if (cameraPosition.magnitude > threshold)
        {
			foreach (Transform child in parentGameObject.transform)
			{
				child.transform.position -= cameraPosition;
			}
			gameObject.transform.position = new Vector3(0,0,0);
	    }
    }
}

Thats the best you can do in Unity AFAIK, and basically what @rutter suggested, however its still not optimal.

The above results in thousands of single shifts including a large loop, each frame.
It would be performance-wise much better if I could group all objects under a “Drag” or “Anchor”-like empty gameobject, that is once shifted (including the children) for the required distance, and then reset to the origin (without the children). Doing that manually is even worse than the above code.
However, shifting lots of objects by its parent is faster, but to realize Floating Origin with that you need a function to independently reset the parent.

So an additional function to transform a parent gameobject without the children would be the key here.

Old post, yet I had the same problem.

.

Some objects were deep in a hierarchy and the parents had x,y,z position would be better if they were at (0,0,0). If you adjust the parent directly to the origin, all the children shift as well.

.

I figured out a way to keep the children in place in the editor.

.

Create a new Empty GameObject as a sibling of the Parent. This will naturally be at (0,0,0).

.

Drag the children into that Empty GameObject. The editor will adjust the coordinates of the children.

.

Save the name of the old parent

.

Delete the old parent.

.

Rename the Empty Gameobject to have the same name as delete parent.