Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Dsiable selection outlines on object

Discussion in 'Editor & General Support' started by kendallroth, Jan 26, 2022.

  1. kendallroth

    kendallroth

    Joined:
    Nov 4, 2015
    Posts:
    20
    I am creating a custom editor window and would like to be able to disable the selection outline (both "Selected Outline" and "Selected Children Outline") when working with certain objects in the scene. I have not been able to find any documentation regarding this, but think I have seen similar behaviour in other packages before. The end goal is to indicate my own selection in the Unity editor when working with specific game objects; any help would be greatly appreciated!

    I spent a while trying to get this work by changing/resetting the associated colours in Editor Prefs, but could never actually get them to work (only received errors or nothing). Also, since setting the opacity to 0 doesn't really seem to do anything, I'm not sure that this would have worked anyway.
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    jmortiger, hippocoder and kendallroth like this.
  3. kendallroth

    kendallroth

    Joined:
    Nov 4, 2015
    Posts:
    20
    @fffMalzbier thank you kind sir for pointing me in the right direction! Once I realized the colours were being used in a gizmo, I was able to redirect my search to disabling gizmos. This led me down the rabbit hole of reflection (based on a superb answer here), but eventually I was able to easily disable the `showSelectionOutline` gizmo (far, far superior to my previous idea)!

    Code (CSharp):
    1.     private void ToggleSelectionGizmo(bool enabled)
    2.     {
    3.         Type AnnotationUtility = Type.GetType("UnityEditor.AnnotationUtility, UnityEditor");
    4.         var ShowOutlineOption = AnnotationUtility.GetProperty("showSelectionOutline", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
    5.         ShowOutlineOption.SetValue(null, enabled);
    6.     }
     
    jmortiger, hippocoder and fffMalzbier like this.