Handles.Label with constant size (not scale based on distance to camera)

How can I have Handles.Label have a constant size? It scales automatically when I move the camera in order to occupy the same space in the scene view, but I would like to have a constant world size instead.

I had the same issue with a waypoint system I am working on where I wanted to draw information about each waypoint in the scene view using Handles.Label. The labels would scale up the further away the scene view camera was and it would become a mess to look at.

I ended up going with the solution on this thread:

https://forum.unity.com/threads/very-small-request-handle-label.107333/#post-726267

It only draws the label if the scene view camera is within a given range.

I edited the code a bit to look like:

public static bool IsSceneViewCameraInRange(Vector3 position, float distance)
{
    Vector3 cameraPos = Camera.current.WorldToScreenPoint(position);
    return ((cameraPos.x >= 0) &&
    (cameraPos.x <= Camera.current.pixelWidth) &&
    (cameraPos.y >= 0) &&
    (cameraPos.y <= Camera.current.pixelHeight) &&
    (cameraPos.z > 0) &&
    (cameraPos.z < distance));
}

Then when I want to draw a label:

if (IsSceneViewCameraInRange(somePosition, someDistance))
{
     Handles.Label(somePosition, someText);
}

There’s probably a better way, but this works pretty well in my case.

1 Like