How to instantiate a GameObject in a scene and keep world transform?

There is next in API:

public static Object Instantiate(Object original, Transform parent, bool instantiateInWorldSpace);

But I need next:

public static Object Instantiate(Object original, bool instantiateInWorldSpace);

I need to instantiate it in a scene without parenting, but keep world transform.

Just instantiate it without assigning a parent. You only need to set instantiateInWorldSpace when you’re assigning a parent during instantiation. Otherwise without a parent all you have is world space, so that bool would be meaningless even if it were available.

public static Object Instantiate(Object original);

Why not just do it this way?

GameObject nameOfGameObeject = Instantiate (Resources.Load ("preFab"), transform.position, new Quaternion ()) as GameObject;
nameOfGameObject.position = newPosition;

The reason this is happening to you is that the transform.position value is always relative to the parent (or much more the whole transform is).


The first cube is assigned to your parent GameObject that’s positioned at (-5, 0, 0) in the video. For that reason, the child cube with the transforms local position being set to (0, 0, 0) is shown at (-5, 0, 0) in the world space (~both positions added).


If you copy that cube and paste it somewhere else like that, it’s position will be relative to its new parent, which is in this case the - let’s call it - ‘root’ transform, that (if it existed) had a position (0, 0, 0), rotation (0, 0, 0) and a scale (1, 1, 1).


Maybe you can try to instantiate the second cube keeping the parent as @LilBoWeep and @Joe-Censored suggested and then afterwards move it outside. I know that this works when you are doing it by hand in the hierarchy but never tested it from code, would be interestening to know!