"Screen position out of view frustum" error on startup

Hello,

I started a new project in unity recently. For now, it only has a camera, a script (attached to the camera), and two cubes.
Yet I already have the infamous “Screen position out of view frustum” error EVERY time I start unity. To be more precise, here’s the exact error message

Screen position out of view frustum (screen pos 0.000000, 0.000000, 100.000000) (Camera rect 0 0 0 0)
UnityEngine.Camera:ScreenToWorldPoint(Vector3)
cameraGizmo:OnDrawGizmos() (at Assets/RMAssets/Scripts/Misc/cameraGizmo.cs:17)
UnityEditor.DockArea:OnGUI()


I’ve been searching all around for explanation. But all I could found was “meh it’s an editor bug, just don’t mind it. They’ve never been able to reproduce it”.

So my questions are: Does this bug has been tracked down yet? If not, should I / How do I give a copy of my project to unity devs?

By the way, here’s the script file attached to the camera, I only use it to print the camera field of view (not the full frustrum because I’m working on a 2D game):

using UnityEngine;
using System.Collections;
 
public class cameraGizmo : MonoBehaviour
{
    Camera cam;
 
    void Start()
    {
        Gizmos.color = Color.white;
    }
 
    void OnDrawGizmos()
    {
        Camera cam = this.camera;
 
        Vector3 blPoint = cam.ScreenToWorldPoint(new Vector3(0, 0, cam.farClipPlane));
        Vector3 brPoint = cam.ScreenToWorldPoint(new Vector3(cam.pixelWidth, 0, cam.farClipPlane));
        Vector3 tlPoint = cam.ScreenToWorldPoint(new Vector3(0, cam.pixelHeight, cam.farClipPlane));
        Vector3 trPoint = cam.ScreenToWorldPoint(new Vector3(cam.pixelWidth, cam.pixelHeight, cam.farClipPlane));
 
        Gizmos.DrawLine(tlPoint, trPoint);
        Gizmos.DrawLine(trPoint, brPoint);
        Gizmos.DrawLine(brPoint, blPoint);
        Gizmos.DrawLine(blPoint, tlPoint);
    }
 
    void OnDrawGizmosSelected()
    {
        Gizmos.color = Color.red;
        OnDrawGizmos();
    }
}

Thanks for reading. Any help would be appreciated.

@Hijackedbrain
No, this is not the same as the editor bug.

Change the following lines in your OnDrawGizmos call:

Vector3 blPoint = cam.ScreenToWorldPoint(new Vector3(0, 0, cam.farClipPlane - 0.01f));
Vector3 brPoint = cam.ScreenToWorldPoint(new Vector3(cam.pixelWidth - 0.01f, 0, cam.farClipPlane - 0.01f));
Vector3 tlPoint = cam.ScreenToWorldPoint(new Vector3(0, cam.pixelHeight - 0.01f, cam.farClipPlane - 0.01f));
Vector3 trPoint = cam.ScreenToWorldPoint(new Vector3(cam.pixelWidth - 0.01f, cam.pixelHeight - 0.01f, cam.farClipPlane - 0.01f));

The issue here is that you are attemting to find the out edge of the view frustrum using ScreenToWorldPoint, however the values held by cam.farClipPlane, cam.pixelWidth, and cam.pixelHeight are literally just outside the edge of that frustrum. By subtracing a small value like 0.01f, you are bringing those values back within the view frustrum so ScreenToWorldPoint can actually get a value for their location.

I had this error too.

It seems to happen when I create a project in a 14’ laptop, and then copy the entire project folder for a laptop with a bigger monitor (in the case, a 15’ one).

The solution was to recreate the project, and copy all the files (not the folders) necessary for it (.unity, .cs, etc). Maybe it has something to do with the .meta files or the cache (which are copied when you copy the entire folder)…

I didn’t know someone reported this as a bug, maybe they could try to reproduce it this way.

Good luck!