Exclude gameobjects from final build

I have scene with certain gameobjects, some of them are development related only and i’d like to not include them in final build. Is it possible to exclude certain gameobject with their childs from final builds.
For now the only solution i see is deleting the gameobjects, build and undo, but that doesnt really seem very practical and safe.

1 Like

Actually, this is exactly what the EditorOnly tag is for. If tagged using the built-in EditorOnly tag, a game object will appear in the editor (including playmode, I believe) but will be removed in any actual builds.

Assuming it’s okay to change the tag of the game object, anyway. Otherwise your best bet is to use an OnPostProcessScene callback that removes unwanted game objects right before the scene is built.

It’s probably too late given the age of this question, but for anyone who stumbles across this thread in the future, these ways are probably the easiest.

I don’t think there’s any nice way to do this in Unity at the moment. What you would have to do is to create your own menu item or GUI somewhere which triggers a build via the BuildPipeline. That way you can perform some processing before building, for example, load a level and delete objects, and then kick off the build. You will want to make sure that you switch to a new empty scene after the build finishes, otherwise if you leave the level open, it will have your modifications in it and you might accidentally save them.

You can use EditorBuildSettings.scenes to get a list of all scenes that have been added to the project (however, the documentation seems to be missing for this on the Unity web site).

Another way to do this is to use conditional compilation to include code only when in the editor (that won’t work if you really do need to get rid of the entire GameObject though).

Scripts in the WebPlayerTemplate don’t get compiled, maybe the same for gameobjects?