Creating gameobject with default rename support [editor code]

Hi, In hierarchy right-click->create empty creates an empty game object. I want this to happen from editor code.
I am using:

var g = new GameObject(myName);

And also tried:

var g = EditorUtility.CreateGameObjectWithHideFlags(g_name, HideFlags.None);

But this already creates the game object with “myName” without giving me the chance to change the name myself. If I wish to rename it then I have to again select it and rename it. I want the default way of creating game object from editor code.

Use Selection.activeGameObject = g; after creating your object to automatically select it.

Thank you. That did it!

1 Like