Select un-selectable Objects with mouse.

(Problem)

I have came across a pretty annoying issue, I need to select a game object that does not have a single selectable component. Which is infuriating because I have alot of those kinds of objects, I need a handle, gizmo, or a dummy object that only has a presence in editor, that I can click on in the editor. I want to see if the community has a solution first before I try to make one.

(Context)

I made a pathfinding system involving a lot of waypoints for a complex 2D platformer.
All the waypoints sit on a single parent named Waypoints, There is at least 100 or more waypoints. My current way to select a object is to scan through the objects to find the one I want to edit. Do to the nature of the garbage collector, it has to dispose of memory often because what I’m assuming is the inspectors fault, Leaving a small delay before I can continue scanning through the objects, Annoying and a little bearable but definatly adding to the currently fubar situation.

(What I hope exists)

An example script to help select those un-selectable objects(With a mouse).

A handle function(that I haven’t found by name) so I can make a editor script for the waypoint comp to make it selectable.

Something that exists in the doc that pertains to this situation.

A feature request link, so I can upvote it.

You can draw handles using the Handle class:

You can use Gizmos to draw the Spheres in the scene:

And you can detect the intersection of a ray and a sphere using this code:

public static bool IntersectRaySphere(Ray ray, Vector3 sphereOrigin, float sphereRadius, ref float t, ref Vector3 q)
{
	Vector3 m = ray.origin - sphereOrigin;
	float b = Vector3.Dot(m, ray.direction);
	float c = Vector3.Dot(m, m) - (sphereRadius * sphereRadius);
	// Exit if rís origin outside s (c > 0)and r pointing away from s (b > 0)
	if ((c > 0.0f) && (b > 0.0f)) return false;
	float discr = (b * b) - c;

	// A negative discriminant corresponds to ray missing sphere
	if (discr < 0.0f) return false;

	// Ray now found to intersect sphere, compute smallest t value of intersection
	t = -b - Mathf.Sqrt(discr);

	// If t is negative, ray started inside sphere so clamp t to zero
	if (t < 0.0f) t = 0.0f;
	q = ray.origin + t * ray.direction;
	return true;
}

t is the distance to the sphere, q is the point of collision.

ray is the Ray to the scene from the camera, which you can calculate using

var ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

sphereOrigin is the position of each waypoint.

sphereRadius is the radius of each waypoint.

What you need to do is that when your Waypoints GameObject is selected, you will display all the waypoints using Gizmos.DrawSphere.

When the user clicks in the scene:

var mouseUpEvent = Event.current.type == EventType.MouseUp;

you will then use the IntersectRaySphere function above to detect if a sphere/waypoint was clicked and store the reference to it (you will have to iterate all the waypoints).

With a reference to a waypoint (and it’s data) you can draw a position Handle with Handles.PositionHandle, which will allow you to edit the position of the waypoint.