Gameobject in scene but missing in hierarchy?
Hi,
I recently dragged and placed a prefab into my scene (a building part) and then subsequently deleted this from the scene by clicking on it in the scene view and hitting delete.
This popped up a message saying this would break the instance of the prefab. (I assume as I deleted a child rather than the actual parent); however, this Gameobject was removed entirely from the hierarchy.
Now when I start the game, the object still exists (I can't actual see it but as it's a building part I know it follows my mouse until I click the left mouse button to place it on the terrain). Once placed I can jump on and off it and collide with it, but it still does not exist in the hierarchy.
I really want to be able to delete it but I cannot seem to find a way of doing this now it no longer exists in the hierarchy?
I have used the search function on the hierarchy but this shows no results for anything related to the building part.
Has anyone got any experience with this issue or is it a known bug?
Ste.
There are always some hidden object exist in scene with null reference made by some plugins.
And you can delete that object by clicking it on Scene and press Delete.
Hey,
The problem is the object is invisible in scene. So unfortunately I can’t click on it. I think I deleted the child that contained the mesh renderer.
Any other way of finding all objects that exist in scene? Other than searching hierarchy?
Ste
You can get all object in scene and look for null component. The only hidden object in scene I know of is _Dispacher with null script inside it like it was made of C++ object.
Thanks for the help!
I've implemented the steps suggested and returned 20 null gameobjects, 19 of which are objects I have set to be inactive in the hierarchy and 1 of which is my 'invisible' gameobject called "$$anonymous$$Bfoundation".
Somehow the hideflag attribute had been altered to hide the object.
Anyway I wrote an editor script to make it unhide and then deleted it. Viola!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Scene$$anonymous$$anagement;
using UnityEngine.Scene$$anonymous$$anagement;
[InitializeOnLoad]
public class DeleteObject : Editor {
static DeleteObject() {
List<GameObject> rootObjects = new List<GameObject>();
// get root objects in scene
Scene scene = Scene$$anonymous$$anager.GetActiveScene();
scene.GetRootGameObjects( rootObjects );
// iterate root objects and do something
for (int i = 0; i < rootObjects.Count; ++i) {
GameObject gameObject = rootObjects[i];
if (gameObject != null) {
Debug.Log ("Found the hidden passage");
if (gameObject.name == "$$anonymous$$BFoundation") {
gameObject.hideFlags = HideFlags.None;
}
}
}
}
}
Answer by basil3 · Aug 23, 2018 at 06:04 PM
Here was the answer:
The GameObject was hidden in the hierarchy as its hideflag attribute had been changed (for some unknown reason). The following script can be placed into a folder called Editor and placed in your main assets folder. Assets >> Editor.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
[InitializeOnLoad]
public class DeleteObject : Editor {
static DeleteObject() {
List<GameObject> rootObjects = new List<GameObject>();
// get root objects in scene
Scene scene = SceneManager.GetActiveScene();
scene.GetRootGameObjects( rootObjects );
// iterate root objects and do something
for (int i = 0; i < rootObjects.Count; ++i) {
GameObject gameObject = rootObjects[i];
if (gameObject != null) {
Debug.Log ("Found the hidden passage");
if (gameObject.name == "MBFoundation") {
gameObject.hideFlags = HideFlags.None;
}
}
}
}
}
Massive thanks to @NoDumbQuestion for the help on this one!
@basil3 Thank you so much for leaving this here for everyone to find.. Much Love! <3 Helped me out huge!!
I got the name of each gameobject and found the one that was hidden, then deleted it by using the following if statement: Debug.Log (gameObject.name); if (gameObject.name == "Vine Bottom") { DestroyImmediate(gameObject); }
Your answer
Follow this Question
Related Questions
Hierarchy objects deleted and 999+ errors when adding terrain 0 Answers
Game running different depending on what is selected in hierarchy. 0 Answers
Why won't my downloaded asset appear in the scene or hierarchy? 1 Answer
Dont destroy on load results in new scene with all deleted objects c# 1 Answer