Search Unity

Hide object in Hierarchy, but still allow selection

Discussion in 'Scripting' started by joshcamas, Jun 15, 2018.

  1. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,277
    Hello friends :)

    I have an object that I want to hide from the hierarchy, but I still want to be able to select it (or at the very least, somehow detect clicking it). Is there a way to do this? Thanks!

    EDIT: I tried adding a collider to the object, then on scene click, shoot a ray from the camera, and it works.. ALMOST? I can detect right mouse up, but not left mouse up...

    Also, (not really related but I didnt want to make another post) is it possible to make it look like I'm selecting a gameobject, when in the inspector it's showing another selected object?

    Josh
     
    Last edited: Jun 15, 2018
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Regarding your first question:
    Do you want to hide it in the hierarchy structure of the unity editor? Or do you just want to hide it?
    If you just want to hide that object as well as its child objects, add a CanvasGroup component to the parent and set the alpha value to zero.

    second question:
    Really not sure what you want to achieve... maybe you can tell your exact use case.
     
    joshcamas likes this.
  3. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,277
    I simply want to make the object hidden in the structure.

    My goal for this is I want a clickable mesh in the editor (that wont be saved or shown in hierarchy) that upon clicking it, looks like I'm editing that mesh but in truth I'm editing a scriptable object. (Object in inspector in scriptable object).

    Clearly a super duper strange request, I'm basically making a system that keeps character/item spawn points separate from the scene data, but I want to make it have the same functionality as a normal gameobject in the editor (aka clickable to edit)
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I believe you're looking for this.

    https://docs.unity3d.com/ScriptReference/HideFlags.HideInHierarchy.html

    But I have to say, please don't do this for any asset you intend on selling on the asset store. The first time I removed an asset I had purchased from my project that had placed a hidden object in my scene hierarchy it took me several hours to figure out where the hell these missing components warnings were coming from and figure out how to remove the object. Beyond frustrating.
     
    BikramKumar and syscrusher like this.
  5. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,277
    Yes, that's what I've tried... sadly, this means the user cannot select the object.
     
  6. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    1,104
    Thanks very much for this post. I am working on a new version of an asset myself, and I came to this thread seeking a way to hide the object while still allowing it to be a clickable selection target from the Scene View. You make a really good point that I hadn't considered, and I intend to heed your warning.
     
  7. Deleted User

    Deleted User

    Guest

    Looking for a solution to this issue myself.

    Edit

    Found solution
    Code (CSharp):
    1.  
    2.         private void DuringSceneGUI(SceneView sceneView)
    3.         {
    4.             switch (Event.current.type)
    5.             {
    6.                 case EventType.MouseEnterWindow:
    7.                     objectList.ForEach(x => x.hideFlags = x.hideFlags & ~HideFlags.HideInHierarchy);
    8.                     break;
    9.                 case EventType.MouseLeaveWindow:
    10.                     objectList.ForEach(x => x.hideFlags = x.hideFlags | HideFlags.HideInHierarchy);
    11.                     break;
    12.             }
    13.         }
     
    Last edited by a moderator: Jan 24, 2020
    Darkgaze, joshcamas and syscrusher like this.