Hello everyone, I need to hide some GOs from the Scene view (meaning, turning off the eye icon in the Hierarchy). So I found this seems the way to go: Code (CSharp): using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; using UnityEngine.UI; using UnityEditor; [ExecuteInEditMode] public class CameraZonesVector : MonoBehaviour { SceneVisibilityManager.instance.Hide(this.gameObject, true); } If I drop this script in a GO, it works just fine: it hides both the parent GO and all its childs. The problem is that —even if I don´t use the script in the scene— when I try to make an Android build, it complains saying this: error CS0103: The name 'SceneVisibilityManager' does not exist in the current context Any hints on this? I hardly find any references in the web to this issue... Thank you all in advance, have a great day!
You really shouldn't mix game and editor code. But if you really-really-really want to, always put your editor code in Code (CSharp): #if UNITY_EDITOR [...] // unity editor code goes here #endif including your use of using UnityEditor;. BTW, what is that class you put here? It looks 'funny'. Maybe you're missing a method declaration and stuff?
This is part of the UnityEditor namespace: https://docs.unity3d.com/ScriptReference/SceneVisibilityManager.html It is for editor-time use only.
This... ^ ^ ^ and for certain applications you can also use partial classes to stick parts of your code in a completely-#ifdeffed-out file (that has to be in the same assembly obviously, not in a folder called Editor!)
Hey, so, the problem is that there is two main namespaces - UnityEngine and UnityEditor. The first one is wrapper over c++ engine, which we call from C# in order to create game logic. It contains all the classes we need for that. The second one, UnityEditor dedicated for Editor-specific things, like, sliders, editors, internal UI and so on. One of these is SceneVisibilityManager. The problem is, you can't ship your game with UnityEditor classes, because you have it only in context of Editor. So, by the end of the day, you have to get rid of all the UnityEditor usages in your runtime code. But I assume you want to hide your object in runtime, not in Editor. There are a few ways to do that, but the most easiest one is to just disable it. https://docs.unity3d.com/ScriptReference/GameObject.SetActive.html If you want it to keep working, but being invisible, probably I'd put your visible part of it a into child and disable this child.
Lurking-Ninja, Kurt-Dekker and mishakozlov74, thank you so much for your time to answer my question! With all the knowledge you shared with me so generously, I´ll fix this problem, and upload the script, in case anyone may find it useful for their own work. Again, guys, no words to thank you! Have a great day!
Of course you're welcome. Always good to see someone diligently tracking down an unexplained situation and trying all kinds of reasonable things to figure out what was going on, and then you made a good post explaining your whole process, which makes it easy for us to look at and go "Ah, I bet it was this issue..." Dive right in, the water's fine! Unity3D is the best game engine ever. Get it all over your brain and you will learn more and more amazing things and eventually you will even impress yourself with what you can do.