Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Delete GameObjects from scene in editor (not during play)

Discussion in 'Scripting' started by unity_q1pZ8A_S5IBFOw, Sep 3, 2020.

  1. unity_q1pZ8A_S5IBFOw

    unity_q1pZ8A_S5IBFOw

    Joined:
    Mar 22, 2019
    Posts:
    2
    I cannot seem to find how to remove a GameObject from a scene that is currently being edited.
    I am creating an editor menu that helps manage scene objects and need to replicate what happens when you right click a GameObject in the scene and select Delete.

    Destroy seems to be related to objects at runtime, and does not work.

    Any help is much appreciated.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,947
    Does
    DestroyImmediate
    work?
     
  3. unity_q1pZ8A_S5IBFOw

    unity_q1pZ8A_S5IBFOw

    Joined:
    Mar 22, 2019
    Posts:
    2
    Code (CSharp):
    1. DestroyImmediate
    did the trick.

    Thank you for the help @PraetorBlue