I have run up on some sort of phantom sprite or gameobject in the scene view that is visible in the game that I cannot select and is not visible in the hierarchy. It is a placeholder obstacle I have made for my game; however, I did not place this one here. (The bright green triangles that jut into the game window)
Alright now I feel stupid for asking this question but I’ll write the solution here for anyone that runs into the same problem. You have to go to your Assets folder and create a new folder titled Editor. Create a new C-Sharp script in this folder titled HiddenObjectExplorer and copy and paste this editor script created by @Bunny83
///
/// author: Bunny83
/// forum thread: https://discussions.unity.com/t/cant-remove-gameobject-from-scene-in-editor-not-appear-in-heirarchy-not-selectable-ghost-object/101058/2
/// direct file source: https://www.dropbox.com/s/b8s70bf5ighi8p3/HiddenObjectExplorer.cs?dl=0
///
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
public class HiddenObjectExplorer : EditorWindow
{
[MenuItem("Tools/HiddenObjectExplorer")]
static void Init()
{
GetWindow<HiddenObjectExplorer>();
}
List<GameObject> m_Objects = new List<GameObject>();
Vector2 scrollPos = Vector2.zero;
void OnEnable()
{
FindObjects();
}
void FindObjects()
{
var objs = Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[];
m_Objects.Clear();
foreach(var O in objs)
{
var go = O.transform.root.gameObject;
if (!m_Objects.Contains(go))
m_Objects.Add(go);
}
}
void FindObjectsAll()
{
var objs = Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[];
m_Objects.Clear();
m_Objects.AddRange(objs);
}
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 top level"))
{
FindObjects();
}
if (GUILayout.Button("find ALL object"))
{
FindObjectsAll();
}
GUILayout.EndHorizontal();
scrollPos = GUILayout.BeginScrollView(scrollPos);
for(int i = 0; i < m_Objects.Count; i++)
{
GameObject O = m_Objects[i];
if (O == null)
continue;
GUILayout.BeginHorizontal();
EditorGUILayout.ObjectField(O.name, O,typeof(GameObject),true);
HideFlags flags = O.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);
O.hideFlags = flags;
GUILayout.Label(""+((int)flags),GUILayout.Width(20));
GUILayout.Space(20);
if (GUILayout.Button("DELETE"))
{
DestroyImmediate(O);
FindObjects();
GUIUtility.ExitGUI();
}
GUILayout.Space(20);
GUILayout.EndHorizontal();
}
GUILayout.EndScrollView();
}
}
Now go up to Tools and click HiddenObjectExplorer. A new window should pop up. Uncheck HideInHierarchy for anything that should not be hidden.
You can delete any objects from here, but I recommend you go back to the hierarchy to delete anything only because the HiddenObjectExplorer delete buttons are fairly close to each other and you might accidentally delete something you didn’t mean to. But once that’s done you should be good!
Just meet the problem today, I dragged a sprite to scene while the editor start an auto recompiling, then a sprite appears in scene but i can’t find it in hierachy. I did a simple operation to delete the mising sprite object. Just set all objects in hierachy inactive, the click the scene view press “ctrl+A”, this will select all objects in scene which is active, in this case is only the missing sprite, then I can delete it by pressing “delete” key on keyboard. Hope can help other people who meet the same problem.