Clickable empty GameObject in the editor

Hi,

EDIT: I already found a solution (see below).


I want to create some waypoints, and I want to be able to select them in the editor window. Currently I use empty GameObjects with a Waypoint script attached, which draws gizmos for them. But I cannot select them in the Editor, because there is nothing to select (no geometry, only the gizmo).

But I want to be able to select them in the editor, like one can select a camera object. Does anyone know a solution to this?


EDIT: Like always, I found the solution right after I posted the question. It seems that Gizmo.DrawCube is not clickable, but Gizmo.DrawIcon is - I don't quite know why, but okay, now it works. If someone knows WHY this works this way or how to have a clickable Gizmo.DrawCube - thats the question know :)

Solution found, see EDIT in my question. This answer is just to clean things up (so everyone looking for it can find it solved).

It seems that Gizmo.DrawCube is not clickable, but Gizmo.DrawIcon is.

I’ve found that by attaching a mesh to my waypoing object, I’ve been able to select and move it around inside the editor with clicking/dragging.

Unfortunately this answer didn’t work for me - though I’m not sure if it’s because I used a custom Gizmo icon or not.

My alternative which seems to be working pretty well is as follows:

Using a 3D / 2D mesh renderer (I used a 3D Sphere Mesh with a flat white material - though a Sprite Renderer will probably work just as well) I am able to select and manipulate the Waypoint as easily as any other object.

Then, in the script I use to manage my waypoints, I loop through every instance of a waypoint and then Destroy the MeshRenderer component on void Start (). This means that while the mesh component is visible in the editor view, all are destroyed immediately upon scene launch and therefore not visible to the player.

Hope this helps somebody!

As of 2022’s Unity the statements are a bit misleading…
The following snippet will create a perfectly clickable 10x1x10 area in my Unity 2021.

Add it to your MonoBehaviour, set alpha to zero and the “click cube” will render invisibly.

void OnDrawGizmos()
{  
        Color oldColor = Gizmos.color;
        Gizmos.color = new Color(1, 0, 0, 0.3f);
        Gizmos.DrawCube(center, new Vector3(10,1,10));
        Gizmos.color = oldColor;
}