Search Unity

Question How do you make handles show even if the GameObject is not selected?

Discussion in 'Editor & General Support' started by TheCelt, Nov 5, 2022.

  1. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    742
    As per the title, I want to see all the handles on a prefab in the scene without having it selected. Currently it only shows if I have selected it which is super annoying as I want some text labels in the editor window whilst I am debugging.

    How do you do this ?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,748
    I usually just use OnDrawGizmos for important bits of my prefabs, but I think what you want actually might be possible.

    I base this "think" on the BezierSolutions package in the asset store. It's free and it implements a OnSceneGUI() that draws several handles at once on a given object. It might still require at least one GameObject be selected but I haven't fiddled with it much.

    https://assetstore.unity.com/packages/tools/level-design/bezier-solution-113074

    I see it being done in their
    BezierPointEditor.cs
    editor script.
     
    spiney199 likes this.
  3. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    742
    You can't draw handle labels in the gizmo's so i can't get text labels from that.

    And yeah that still requires selecting the game object for the bezier stuff.
     
    Kurt-Dekker likes this.
  4. villevli

    villevli

    Joined:
    Jan 19, 2016
    Posts:
    89
    Attach this kind of script to your gameobject. Note the
    ExecuteAlways
    attribute which should make this work in edit mode as soon as the object is enabled regardless if it's selected or not. If you want to add this into a script that also handles play mode logic you can check
    Application.isPlaying
    in the code.
    Code (CSharp):
    1. using UnityEngine;
    2. #if UNITY_EDITOR
    3. using UnityEditor;
    4. #endif
    5.  
    6. [ExecuteAlways]
    7. public class HandlesBehaviour : MonoBehaviour
    8. {
    9. #if UNITY_EDITOR
    10.     private void OnEnable()
    11.     {
    12.         SceneView.duringSceneGui += OnSceneGUI;
    13.     }
    14.  
    15.     private void OnDisable()
    16.     {
    17.         SceneView.duringSceneGui -= OnSceneGUI;
    18.     }
    19.  
    20.     private void OnSceneGUI(SceneView sceneView)
    21.     {
    22.         // Draw your handles here
    23.     }
    24. #endif
    25. }
    26.  
     
    SelvaB likes this.
  5. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,935
    Have you tried? You might find that you actually can.