Hide gameObjects from game camera or scene-view


Sometimes you want to show or hide some gameObjects without actually desactivating them in the hierarchy. This article show 2 built-in methods to do the following:
  • Hide/show gameObjects in game, but show them in the sceneView
  • Hide/show gameObjects in the scene-view, but show them in game

Hide gameObjects from the Main Camera


First, you need to create a Layer named

EditorOnly
. Go to the layer tab, and create a new Layer. Then apply this layer to all gameObjects you want to hide from the game camera

gameObejct to hide:






Here is where the magic append, select your main camera, and disable from the culling mask the layer

EditorOnly
. Enjoy the result below.










Hide gameObjects in the scene view


There is 2 ways on hiding gameObject in the scene view in unity.

First, you can choose to hide an entire layer. Notice the
next to each layer. You can click on them to hide, or show all the gameObjects on these layer.

By the way, you can also lock them, to disalow the selection in the scene view.
The second method required the last version of Unity. Since Unity 2019, you can also hide individually each gameObject, by clicking on the little eye next to each gameObjects.


If you have gameObjects not shown in the game, you could also tag them as
EditorOnly
, (with tag, not layer) to simply remove them from the build. More Info in my article below.









See also:

EditorOnly Components and Actions when building

This article show how to remove components you don't want in build while keeping them in gameObjects, and how to execute actions when you are building your application


Enhance any built-in components of unity

Add behavior of any unity components using customs inspectors and reflection