- Home /
Can't remove GameObject from scene in editor (Not appear in heirarchy, not selectable, Ghost object)
No, this is not an April fools joke.
I was adding capsules to the scene and eventually I noticed this capsule in my scene. It does not appear in hierarchy, I cannot select it in the editor.
You can see in this image the said capsule, and with all objects deactivated in the hierarchy.
Please help! I've tried changing scenes, I've tried restarting the client. I would make a new scene but I'd really prefer to know what's going on here, and how to fix or avoid it in the future.
Just to see what happens, click-on/highlight your scene asset in the project panel and hit cntrl+D to duplicate it. Then open that scene and see if the phantom still lurks.
Yep, still there. Same place, no change in hierarchy.
Edit: I made a new scene and copied over my asset, and the ghost was not found. I'd still like to know why it's in my original scene however.
@Jazzer008:
Have you tried the editor script i posted in my answer? Have you finally found the object?
Answer by Bunny83 · Apr 01, 2014 at 04:52 AM
Well, the capsule might be a normal capsule object but the hideFlags have been set to a combination of HideInHierarchy, HideInInspector and NotEditable. However on a normal capsule you usually don't see the wireframe of the mesh unless you select it.
It might be just a gizmo / handle of an editorscript.
If it's a real object you can try this editor script which i just wrote. Just place it in your project's editor folder:
/Assets/editor/HiddenObjectExplorer.cs
You can open the window by clicking "Tools/HiddenObjectExplorer". It might take a few sec. until the Tools menu appears. Just open another menu, that usually makes it visible.
With this window you can view and edit all objects in the scene, even internal objects. Watch out! If you destroy an internal Unity object such as SceneCamera, SceneLight, PreviewCamera, PreRenderLight, HandlesGO and others the editor might fail, crash, spams errors .... So watch out what you're doing.
I've updated the script so you can view all objects, not just the top level objects. Note: If you have a lot of objects in the scene it might lag a bit.
Thanks for the script. I had a similar issue where there was an object in my scene, but not in the hierarchy and I couldn't select or do anything with. I used your script and found out that for some inexplicable reason, this object was set to HideInHierarchy. I think there is a bug in Unity that can set this flag.
Thank you so much, this simple file was extremely helpful.
Thank you for this script! Genius! I had a corrupt object in my scene and selecting it in the hierarchy caused Unity to consume large amounts of resources but never respond again. This saved me a ton of headache!
Thanks, this works great. I used an external tool for something like 3D Notes and when I deleted it all my scenes were reporting missing $$anonymous$$B. Turns out the extension dirtied all scenes with a hidden GO, even those it wasn't used on. After deleting it with this tool, it is required to make another change in the scene (e.g. create empty and delete it) and only then save will work, since otherwise Unity does not mark scene as dirty when you delete the culprit.
Answer by TheGering · Aug 04, 2016 at 07:17 PM
Thanks for the script, it helped me a lot! Well here is an improved version with top and hidden filter.
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
public class ObjectExplorer : EditorWindow {
[MenuItem("Tools/Object Explorer")]
static void Init() {
GetWindow<ObjectExplorer>();
}
readonly List<GameObject> objects = new List<GameObject>();
Vector2 scrollPos = Vector2.zero;
bool filterTop = true;
bool filterHidden = false;
void OnEnable() {
FindObjects();
}
void AddObject(GameObject obj) {
if (filterTop) {
obj = obj.transform.root.gameObject;
}
if (filterHidden) {
if ((obj.hideFlags & (HideFlags.HideInHierarchy | HideFlags.HideInInspector)) == 0) return;
}
if (!objects.Contains(obj)) {
objects.Add(obj);
}
}
void FindObjects() {
var objs = Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[];
objects.Clear();
foreach (var obj in objs) AddObject(obj);
}
HideFlags HideFlagsButton(string aTitle, HideFlags aFlags, HideFlags aValue) {
if (GUILayout.Toggle((aFlags & aValue) > 0, aTitle, "Button")) {
aFlags |= aValue;
} else {
aFlags &= ~aValue;
}
return aFlags;
}
void OnGUI() {
GUILayout.BeginHorizontal();
if (GUILayout.Button("find objects")) FindObjects();
filterTop = GUILayout.Toggle(filterTop, "only top objects");
filterHidden = GUILayout.Toggle(filterHidden, "only hidden objects");
GUILayout.EndHorizontal();
scrollPos = GUILayout.BeginScrollView(scrollPos);
for (int i = 0; i < objects.Count; i++) {
GameObject obj = objects[i];
if (obj == null) continue;
GUILayout.BeginHorizontal();
EditorGUILayout.ObjectField(obj.name, obj, typeof(GameObject), true);
HideFlags flags = obj.hideFlags;
flags = HideFlagsButton("HideInHierarchy", flags, HideFlags.HideInHierarchy);
flags = HideFlagsButton("HideInInspector", flags, HideFlags.HideInInspector);
flags = HideFlagsButton("DontSave", flags, HideFlags.DontSave);
flags = HideFlagsButton("NotEditable", flags, HideFlags.NotEditable);
obj.hideFlags = flags;
GUILayout.Label("" + ((int)flags), GUILayout.Width(20));
GUILayout.Space(20);
if (GUILayout.Button("DELETE")) {
DestroyImmediate(obj);
FindObjects();
GUIUtility.ExitGUI();
}
GUILayout.Space(20);
GUILayout.EndHorizontal();
}
GUILayout.EndScrollView();
}
}
Nice variant! I'll use this one in my project then. I put scripts that are useful for any kind of projects in submodules that I share publicly on BitBucket (mainly because it makes it easier for my colleagues to clone projects using these submodules). So you may find this script on this repository https://bitbucket.org/hsandt/unity-commons-editor/src with the appropriate credits (Bunny83 and you) in a few days. Thanks again to both of you!