Search Unity

How to Pick Gizmos?

Discussion in 'Immediate Mode GUI (IMGUI)' started by bibbinator, Jun 1, 2011.

  1. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    According to the doc gizmos drawn in OnDrawGizmos are pickable, but I can't seem to figure out how to do this.

    I draw the gizmos and I can see them in the scene editor but I can't figure out how to test/know when they're clicked on.

    Any help really appreciated. I can't find anything on this.

    Cheers
     
  2. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    Bump.

    Really stuck on this and not wanting to roll my own dynamic gizmo picking code. Any help appreciated.
     
  3. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
  4. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    8 years later ... and I see @bibbinator now works for UT ;) so I'm hoping we can get an answer ... this core feature of Unity Editor appears to have been broken since Unity version 2.5 (c.f.: https://forum.unity.com/threads/unity-gizmos-not-clickable.22728/ ). The 2019 docs still falsely claim that "Gizmos are pickable", but no-one seems to know how (the top Google hits for me are people writing workarounds where they re-implement Gizmos using something else, e.g. Handles, simply to add the missing functionality that the docs claim is there).

    EDIT: Ah, found the problem. Unity docs are indeed wrong. *some* gizmos are pickable. e.g. the solid-versions of Gizmos (DrawCube, DrawSphere) are pickable (although the docs on how to know which one was clicked are still missing), but the majority (DrawWireCube, DrawWireSphere, DrawLine, etc) are *not* pickable.

    (in case anyone says "Duh! Obvious!" this is not at all obvious: the standard in ALL vector-editing software for 20+ years has been that lines etc are selectable because the picking code looks for mouse-clicks within +/- 5 pixels or so of each line. It's not unreasonable to think Unity would be doing that. Also: even clicking on the exact pixels of lines, wire-cubes, etc ... Unity fails to do a pick operation)
     
    Last edited: Sep 18, 2019
    Tsumoru_ likes this.
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    OK, so... since it sounsd like you figured out how to implement picking of solid gizmos... how do you do it?
     
  6. BrettBibby

    BrettBibby

    Chief Product Officer Unity Technologies

    Joined:
    Mar 24, 2017
    Posts:
    7
    The Unity answers I linked a couple of posts up should still work. But I'll follow up internally and see if I can get somebody to verify this works still, and maybe even make it better out of the box.
     
    JoeStrout likes this.
  7. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    I am confused by this too, I have one gizmo which is a green sphere, can click it fine.. I have another one with the same code which is pink and I cannot select it. I think once I made it wireframe in the past, could that be the reason? Even though that should be forgotten since its not wireframe now. Is it maybe a bug?

    Looks like if its inside another object with a gizo also you cannot select it, very weird. Even pasting it in the root of hierarchy it acts strange, I can then click it after a few attempted but moving it doesd not update the inspector, so I am thinking this is a bug in 2019.4.11f.
     
  8. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    @BrettBibby Now that its been a year. Whats going on with this?
     
  9. ChiwTheNeko

    ChiwTheNeko

    Joined:
    Mar 24, 2022
    Posts:
    136
    In case somebody is still struggling with this, here is the solution (at least the solution for me).

    The culprit is the Gizmo button on the right of the scene view toolbar. If it is not pressed, your custom gizmo will be drawn but won't be pickable. This is where the confusion comes from.

    The solution is not to draw your custom gizmo when the Gizmo button is not pressed. That mean you have to replace this:
    Code (CSharp):
    1. private void OnDrawGizmos()
    2.   {
    3.     Gizmos.DrawIcon(transform.position, "Light_Gizmo.png", allowScaling: false);
    4.   }
    5.  
    By this:
    Code (CSharp):
    1. private void OnDrawGizmos()
    2.   {
    3.     var sceneView = SceneView.currentDrawingSceneView;
    4.     if (sceneView != null && sceneView.drawGizmos)
    5.       Gizmos.DrawIcon(transform.position, "Light_Gizmo.png", allowScaling: false);
    6.   }
    7.