Make custom renderer selectable in scene view

Hi all,

I’m making a custom renderer component that must render a mesh using Graphics.DrawMesh/Graphics.RenderMesh. Problem is, it’s not pickable/selectable in the scene view.

This works fine with the built-in MeshRenderer/SkinnedMeshRenderer even if they have no collider, but haven’t found a reliable or clean way to do this for custom-rendered stuff. The best I’ve come up with is to draw a completely transparent mesh using the DrawGizmo attribute and GizmoType.Pickable, like this:

[DrawGizmo(GizmoType.Pickable | GizmoType.NonSelected | GizmoType.Selected)]
static void DrawGizmos(MyCustomRenderer component, GizmoType type)
{
      if (component.clothMesh == null || Application.isPlaying)
                return;

      var col = Color.white;
      col.a = ((type & GizmoType.Selected) > 0) ? 0.3f : 0;

      Gizmos.matrix = component.transform.localToWorldMatrix;
      Gizmos.color = col;
      Gizmos.DrawMesh(component.customMesh);
}

This only works if gizmos are enabled in the scene view, which makes it very confusing and inconvenient: If you have gizmos disabled, you’re not able to select custom-drawn objects.

Also tried HandleUtility.PickGameObject but this only works for built-in Renderers.

Any way of properly implementing this? thanks!

I wonder if implementing something like OnWillRenderObject() would make it work…?