- Home /
Make New GameObject From Menu Spawn At Zero
Is there any way to make the "Create Empty" GameObject option in the menu (GameObject > Create Empty) spawn the new GameObject at 0,0,0 world space?
Right now it tends to spawn at some irritatingly arbitrary value, 3.3574,4.907523, that sorta thing.
Thanks!
Does anyone know why it doesn't spawn empty game objects at 0,0,0? It is not hard to type 0,0,0 and to make one on top of hierarchy and then copy it, but it should really spawn them at 0,0,0 or at parent's location...
If im not mistaken it spawns at your inspector screen middle with a certain depth, you dont have to type 0,0,0 just RightClick on Transform -> Click Reset => Position = 0,0,0 Rotation = 0,0,0 Scalation = 1,1,1
Answer by Hellium · Sep 21, 2019 at 09:11 PM
A gameObject created using the GameObject > Create Empty
will spawn in the middle of the Scene view. If you want the object to spawn at 0, 0, 0, the scene camera must point at the center of the world.
But, since, Unity is extensible, you can also create your own "Create Empty" menu item thanks to a simple script put in an Editor
folder:
using UnityEngine;
using UnityEditor;
public class CreateEmptyMenu
{
[MenuItem("GameObject/Create Centered Empty #%&n", priority = 0 )]
public static void CreateEmpty()
{
GameObject empty = new GameObject("GameObject");
Undo.RegisterCreatedObjectUndo( empty, "Create new empty" );
Selection.objects = new Object[] { empty };
}
}
Thank you for the script. It works perfectly. $$anonymous$$y question as someone new to C# is, where in that code does it define to spawn a 0,0,0? or is it the lack of defined coordinates that make it default to 0,0,0?
When created, the gameObject also gets a Transform component attached. The default position & rotation or the Transform are respectively the default value of Vector3 ( (0,0,0)
) and the default value of a Quaternion. ( (0, 0, 0, 1)
= (0, 0, 0)
in euler angles))
If you want to force the position of the newly created object:
GameObject empty = new GameObject("GameObject");
empty.transform.position = new Vector3(x, y, z);
Answer by djexstas9 · Mar 04 at 12:55 PM
Actually you can go to Edit -> Preferences -> Scene View and enable the "Create Objects At Origin" toggle. That's it, now your empty objects are created at the scene (0,0,0)
Answer by bubzy · Oct 11, 2014 at 11:29 PM
I dont think so but maybe you could expand the editor and make your own function, is it really a hassle to type 0,0,0 in the inspector though? :)
Answer by MrSoad · Oct 11, 2014 at 11:47 PM
Make one, move it to (0,0,0) give it a name like "1" to keep it at the top of the hierarchy window. Now just duplicate it whenever you need a new one(leaving the original for your next duplication). It's what I do, if you find a better way let me know.
Your answer
![](https://koobas.hobune.stream/wayback/20220613164914im_/https://answers.unity.com/themes/thub/images/avi.jpg)