Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by RowdyMrB · Jan 11, 2014 at 01:56 AM · object

How do I remove a Game Object that is not visible in the hierarchy?

I am receiving a console error ("The referenced script on this Behavior is missing!"). When I double click on it the associated game object is displayed and grayed out in the inspector but cannot be found in the Hierarchy or the Project screens. Likewise, I cannot find it when doing a search of the assets folder outside of Unity. I suspect the object is the result of removing a previously installed package and that there is an an xml file or something like that still referencing the object. Any ideas how to get rid of this object and error?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Jamora · Jan 11, 2014 at 09:14 AM

Because you are able to have the hidden object selected, you can just press Delete while that object is selected.

If you hadn't been able to select it, you would have to write an Editor script to select it for you.

Try this:

 using UnityEngine;
 using UnityEditor;
 
 public class Hider : EditorWindow {
 
     [MenuItem("GameObject_Hider&Destroyer/Start")]
     public static void Create(){
         GetWindow<Hider>();
     }
 
     void OnGUI(){
 
         if(GUILayout.Button("Create hidden GO")){
             GameObject h = new GameObject("hidden");
             h.hideFlags = HideFlags.HideInHierarchy;
         }
         if(GUILayout.Button("Select hidden GO")){
             Selection.activeGameObject = GameObject.Find("hidden");
         }
 
         if(GUILayout.Button("Destory Selected Object")){
             DestroyImmediate(Selection.activeObject);
         }
     }
 }
 
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RowdyMrB · Jan 11, 2014 at 09:01 PM 0
Share

@Jamora,
The script did the trick. I could not select the object as it was grayed out. However, I could see the name of the object and using Selection.activeGameObject = GameObject.Find("GO Name") allowed me to select it DestroyImmediate took care of the rest.
Thank you

avatar image Benproductions1 RowdyMrB · Jan 11, 2014 at 11:44 PM -1
Share

Please do not post comments as answers.

avatar image Benproductions1 · Jan 11, 2014 at 11:45 PM -1
Share

If this answer answered your question you should accept. If you don't know how, watch the tutorial video and read the guidelines in the FAQ on the right.

avatar image
12

Answer by Can-Baycay · Oct 27, 2016 at 10:31 PM

Here is a complete tool to inspect and get rid of hidden game objects easily.

 using UnityEngine;
 using UnityEditor;
 using UnityEditor.SceneManagement;
 using System.Collections.Generic;
 
 public class HiddenGameObjectTools : EditorWindow
 {
     #region Menu Command
 
     [MenuItem("Tools/Hidden GameObject Tools")]
     public static void ShowWindow()
     {
         var window = GetWindow<HiddenGameObjectTools>();
         window.titleContent = new GUIContent("Hidden GOs");
         window.GatherHiddenObjects();
     }
 
     #endregion
 
     #region GUI
 
     private static readonly GUILayoutOption ButtonWidth = GUILayout.Width(80);
     private static readonly GUILayoutOption BigButtonHeight = GUILayout.Height(35);
 
     private void OnGUI()
     {
         GUILayout.Space(10f);
         GUILayout.BeginHorizontal();
         {
             if (GUILayout.Button("Refresh", BigButtonHeight))
             {
                 GatherHiddenObjects();
             }
             if (GUILayout.Button("Test", BigButtonHeight, ButtonWidth))
             {
                 var go = new GameObject("HiddenTestObject");
                 go.hideFlags = HideFlags.HideInHierarchy;
                 GatherHiddenObjects();
             }
         }
         GUILayout.EndHorizontal();
         GUILayout.Space(10f);
 
         EditorGUILayout.LabelField("Hidden Objects (" + HiddenObjects.Count + ")", EditorStyles.boldLabel);
         for (int i = 0; i < HiddenObjects.Count; i++)
         {
             var hiddenObject = HiddenObjects[i];
             GUILayout.BeginHorizontal();
             {
                 var gone = hiddenObject == null;
                 GUILayout.Label(gone ? "null" : hiddenObject.name);
                 GUILayout.FlexibleSpace();
                 if (gone)
                 {
                     GUILayout.Box("Select", ButtonWidth);
                     GUILayout.Box("Reveal", ButtonWidth);
                     GUILayout.Box("Delete", ButtonWidth);
                 }
                 else
                 {
                     if (GUILayout.Button("Select", ButtonWidth))
                     {
                         Selection.activeGameObject = hiddenObject;
                     }
                     if (GUILayout.Button(IsHidden(hiddenObject) ? "Reveal" : "Hide", ButtonWidth))
                     {
                         hiddenObject.hideFlags ^= HideFlags.HideInHierarchy;
                         EditorSceneManager.MarkSceneDirty(hiddenObject.scene);
                     }
                     if (GUILayout.Button("Delete", ButtonWidth))
                     {
                         var scene = hiddenObject.scene;
                         DestroyImmediate(hiddenObject);
                         EditorSceneManager.MarkSceneDirty(scene);
                     }
                 }
             }
             GUILayout.EndHorizontal();
         }
     }
 
     #endregion
 
     #region Hidden Objects
 
     private List<GameObject> HiddenObjects = new List<GameObject>();
 
     private void GatherHiddenObjects()
     {
         HiddenObjects.Clear();
 
         var allObjects = FindObjectsOfType<GameObject>();
         foreach (var go in allObjects)
         {
             if ((go.hideFlags & HideFlags.HideInHierarchy) != 0)
             {
                 HiddenObjects.Add(go);
             }
         }
 
         Repaint();
     }
 
     private static bool IsHidden(GameObject go)
     {
         return (go.hideFlags & HideFlags.HideInHierarchy) != 0;
     }
 
     #endregion
 }
 
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jokerminator · Aug 02, 2019 at 04:27 PM 0
Share

Thank you very much!

avatar image ledshok · Apr 12 at 04:13 AM 0
Share

This script was extremely helpful, thank you!

avatar image
0

Answer by lyzzard · Nov 20, 2016 at 08:16 PM

I had the same issue, so I wrote this very simple script, and it works perfectly.

 using UnityEngine;
 using System.Collections;
 
 // Makes a script execute in edit mode.
 
 // By default, script components are only executed in play mode. 
 // By adding this attribute, each script component will also have 
 // its callback functions executed while the Editor is not in playmode.
 
 // https://docs.unity3d.com/ScriptReference/ExecuteInEditMode.html
 [ExecuteInEditMode]
 public class makeVisible : MonoBehaviour 
 {
     // The functions are not called constantly like they are in play mode.
     // - Update is only called when something in the scene changed.
     void Update () 
     {
         GameObject[] obj = (GameObject[]) GameObject.FindObjectsOfType(typeof (GameObject));
         foreach (GameObject o in obj)
             o.hideFlags = HideFlags.None; // https://docs.unity3d.com/ScriptReference/HideFlags.html
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

draw mesh on top 2 Answers

How to Touch Drag 3D Objects 2 Answers

Manipulating Instanced Object 2 Answers

destroy object after a delay? 6 Answers

CCG: Creating a card object 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges