Search Unity

Scene don't show change when create gameobject by custom script

Discussion in 'Editor & General Support' started by longvk1989, Oct 15, 2016.

  1. longvk1989

    longvk1989

    Joined:
    Apr 10, 2015
    Posts:
    17
    When i use menu GameObject/Create Empty, in hierarchy will add 1 gameobject and the scene header will show a symbol to indicate that the scene has changes like attached file. But when i use custom menu script to create gameobject :

    [MenuItem("Test/Custom GameObject")]
    public static void CreateCustomGameObject()
    {
    GameObject obj = new GameObject();
    }

    in hierarchy will add 1 gameobject but the scene header don't show any symbol to indicate that the scene has changes. If i close unity now, next times when i open unity, the gameobject that i created by custom menu script is not there anymore! How can i force scene to has change and i can save it so next times i won't lose the gameobject anymore
     

    Attached Files:

  2. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
    If you add the action to the undo stack, it should do the trick.
     
  3. longvk1989

    longvk1989

    Joined:
    Apr 10, 2015
    Posts:
    17
    can you give me sample code for it ?
     
  4. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052