"Deleted GameObject" (Hierarchy) - During Build

Ok, it’s not a problem. Everything is fine after the build is finished.

I am simply curious to know why I see this screen while building:

I think the first time I saw it I nearly shat myself. Well, not really, I keep backups.

The scene disappears and hierarchy fills up with ‘Deleted Gameobject’.

Any insight to this strange behaviour?

Actually, this is a bug that happens whenever Unity got range of serialized data, delete all data (so that it got none) and add new data.

Whenever Unity create (instantiate) new objects in an empty serialize range in which the previous content got deleted, it will instantiate the last object it had in its memory and since its deleted, it gets called “deleted gameobject”.

This is due to the fact that, not only in Unity, whenever there’s a serialized range which have been filled, it cannot come back to null/empty without first creating an unique null/emptied gameobject. So if you delete (willingly or not) the content without replacing it, it will stay in the memory as a “deleted gameobject”. (It’s the same thing as an HDD which been formated. Until new data is added, the previous data is still accessible even if it’s invisible)

In the case of building a client/app, the reason why you see this on screen is because Unity convert the whole thing into something else and, by doing so, it’s trying to replace the current data with new data. As I was saying previously, it can’t just delete its memory or it would loose what it’s working on. That’s why the data gets named “deleted gameobject”.

See this as this :

  • You launch the build.
    (Note that all that is following is happening in a temp allocated folder. Your original data is no touched and is backed in another folder)
  • Unity serialize the data to allow it to convert for an app/client.
  • Unity convert all the data for the app/client in the allocated memory.
    (Note that it actually create a converted copy as it’s scanning the data)
  • Unity delete the previous data.
  • Unity add the new converted data in place of the previous as it’s build.
  • Since the new converted data replace the previous deleted data, but it doesn’t necessary read the same way, the system “keep” a backup of the previous data even if it’s temporary deleted… which is why you see “deleted gameobject” while it’s being build.

“deleted gameobject” are simply gameobjects that, once the client close or if a memory sweep is forced in the application will get removed from memory. It’s a way for Unity to allow itself to not bring in errors if, for some reason, something is looking for a gameobject that existed, but not anymore.

This is a common thing whenever you got the system to search through a serialized list to instantiate 3D items and then replace them. I had those “deleted gameobject” all the time in my 3D instantiated text (text made of 3d meshes instantiated in the scene) based on a textfield inputs.