Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by LightStriker · Nov 18, 2013 at 09:57 PM · hidevisibilityshow

Hide Object in Editor Only

I know about GameObject.SetActive or Renderer.enable... However, both offer the problem that if you forget about them, they won't show up in game (or will even turn off scripts and behaviours).

I need a way to hide object only in editor mode, WITHOUT changing the normal in-game behaviour.

Is there such a way?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DavidDebnar · Nov 18, 2013 at 11:39 PM 0
Share

Do you also want to disable their components, or just hide them - make them invisible?

avatar image LightStriker · Nov 18, 2013 at 11:41 PM 0
Share

Invisible, in the Scene View, only in editor mode.

5 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by LightStriker · Nov 19, 2013 at 06:04 PM

The solution we took was rather complex, since every Unity's flags are also used in-game.

We went when a Editor-only dictionary that keeps the real value of visibility of every object. If you modify the visibility manually in the Inspector, we take it as being the real value. If you modify it within our tool, it's a "fake" value that is reverted when you try to save the scene or when you change the play state of the editor.

Using this, our users can hide part of the scene without fear of messing up something in-game.

alt text


hierarchy.png (38.5 kB)
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mikeysee · Jan 02, 2015 at 09:11 AM 0
Share

This is a very clever solution, will work will with UI stuff too

avatar image bobmoff · Mar 07, 2015 at 08:20 PM 0
Share

would you care to share this editor scripts of yours ?

avatar image
7

Answer by nerik · Jan 30, 2014 at 02:50 PM

For me the easiest solution was to use layers. Create a "HideInEditor" layer, then use the dropdown at the top right of the Editor ("Layers") to toggle the layer visibibility.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bobmoff · Mar 07, 2015 at 08:09 PM 0
Share

This does not work for game objects inside canvas

avatar image HendrysTobar bobmoff · Feb 25, 2016 at 05:34 PM 0
Share

If you want to Hide the Canvas UI just hide the layer UI in the Layer Combobox

avatar image
0

Answer by Mene · Nov 18, 2013 at 10:27 PM

edit

I guess you could do this:

 using UnityEngine;
 using System.Collections;

 [ExecuteInEditMode]
 public class HideInEditor : MonoBehaviour {

     void OnEnable () {
         renderer.enabled = !Application.isEditor || Application.isPlaying;
     }

     void OnDisable () {
         renderer.enabled = true;
     }
 }


Not sure if the Application.isEditor test is really needed, but that works for me. Just attach it to what ever you want to hide and hide it by enabling the Behavior. Disabling will show it again.

Before edit

This should do the trick

http://docs.unity3d.com/Documentation/ScriptReference/HideFlags.HideInHierarchy.html

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image LightStriker · Nov 18, 2013 at 10:33 PM 0
Share

It only hide the object from the Hierarchy panel... It doesn't make it invisible on the Scene view.

avatar image Mene · Nov 18, 2013 at 11:30 PM 0
Share

Sorry, missunderstood that

avatar image Mene · Nov 18, 2013 at 11:43 PM 0
Share

I updated my answer. This worked for me.

avatar image LightStriker · Nov 18, 2013 at 11:55 PM 0
Share

And how do I implement that in the scope of a tool? We are rewriting the Hierarchy panel to add new features (such as folders, icon, color, etc). One feature is a "visible" icon to hide and unhide item while editing the level. $$anonymous$$inda annoying to add a $$anonymous$$onoBehaviour around just to make a tool work.

avatar image Mene · Nov 19, 2013 at 12:02 AM 0
Share

I havn't worked with tools much yet. The problem is you would need to enable the renderer again, if and only iff your tool has disabled it. That means you need to react to things like build and the play-button. The easiest way i can come up with right now is to use the tool to attach this behavior to all nodes with your hide-in-editor feature. This would also make sure it works on vanilla unity editors. But as I said I havn't worked much with extensions/tools yet. BTW I think you can use the HideInHierarchy-Property I first sugested to hide the component, too. This way it won't "pollute" the editor view.

avatar image
0

Answer by BillyMFT · Nov 29, 2016 at 01:42 PM

Here's Mene's script adapted for Canvas elements.

 using UnityEngine;
 using System.Collections;
 [ExecuteInEditMode]
 public class HideCanvasElementInEditor : MonoBehaviour {
     void OnEnable () {
         CanvasRenderer[] canvasRenderers = transform.GetComponentsInChildren<CanvasRenderer>();
         float a;
         if(!Application.isEditor || Application.isPlaying){
             a = 1f;
         }else{
             a = 0;
         }
         foreach(CanvasRenderer cr in canvasRenderers){
             cr.SetAlpha(a);
         }
     }
 
     void OnDisable () {
         CanvasRenderer[] canvasRenderers = transform.GetComponentsInChildren<CanvasRenderer>();
         foreach(CanvasRenderer cr in canvasRenderers){
             cr.SetAlpha(1f);
         }
     }
 }


SetAlpha is working for me but there might be a more efficient way of doing it.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by stechmann · Jun 07, 2018 at 01:02 PM

here is a fairly simple solution. create an empty gameobject, attach this script, then simply add all objects you want to hide into the "hide" list:

  using UnityEngine;
  using System.Collections;
  
  [ExecuteInEditMode]
  public class HideInEditor : MonoBehaviour {
  
      public GameObject[] hide;
  
      void Update()
      {
          foreach(GameObject go in hide) {
  
              if (Application.isPlaying)
                  go.SetActive(true);
              else
                  go.SetActive(false);
          }
      }
  }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Object Visibility 2 Answers

Objects Appearing 1 Answer

Unity 2019.4.9f1 - Toggle Show/Hide Gameobject with one keystroke. 1 Answer

[FIXED & CLOSED!] How do I show and hide 3D text? 2 Answers

Re-hiding a guiTexture 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges