Search Unity

Creating gameobject with default rename support [editor code]

Discussion in 'Scripting' started by kaiyum, Jun 27, 2021.

  1. kaiyum

    kaiyum

    Joined:
    Nov 25, 2012
    Posts:
    686
    Hi, In hierarchy right-click->create empty creates an empty game object. I want this to happen from editor code.
    I am using:
    Code (CSharp):
    1. var g = new GameObject(myName);
    And also tried:
    Code (CSharp):
    1. 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.
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
  3. kaiyum

    kaiyum

    Joined:
    Nov 25, 2012
    Posts:
    686
    GroZZleR likes this.