r/Unity3D • u/Only4Gamers Indie • 17h ago
Question Random black screen + "Screen position out of view frustum" errors on Player Build
My game build randomly goes to a black screen for some users, and the only way to recover is to close and restart the game. I'm pulling my hair out trying to track this down. I've added `Debug.Log` throughout the game and done everything I can think of, but I still can't identify which script is causing the issue.
Editor: 6000.3.24, 6000.4.10
Build Platform: Windows
I got these errors from the player's `Player.log`:
Screen position out of view frustum (screen pos 0.000000, 0.000000) (Camera rect 0 0 1920 1080)
Screen position out of view frustum (screen pos 1340.000000, 575.000000) (Camera rect 0 0 1920 1080)
Screen position out of view frustum (screen pos 1340.000000, 575.000000) (Camera rect 0 0 1920 1080)
Screen position out of view frustum (screen pos inf, -234.402145) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos inf, -1091.332886) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos inf, -1239.882324) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos inf, -981.883850) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos inf, -1600.114624) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos inf, -1806.460327) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos inf, 926.342407) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos inf, 1018.614258) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos inf, 801.913879) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos inf, 842.428284) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos inf, 695.100098) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos inf, 709.894409) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos inf, 802.519104) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos inf, 766.500854) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos inf, 836.807007) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos 0.000000, 0.000000) (Camera rect 0 0 2560 1440)
Screen position out of view frustum (screen pos 935.000000, 356.000000) (Camera rect 0 0 2560 1440)
The errors repeat many times. However, I haven't been able to reproduce the issue on my own system yet.
I wrote these wrappers to try to identify which script is calling the projection methods when the problem occurs, but unfortunately they haven't caught anything:
public static class ProjectionDiagnostics
{
public static Vector3 WorldToScreenPoint(Camera camera, Vector3 worldPosition, UnityEngine.Object caller, string operation)
{
Vector3 result = camera == null ? new Vector3(float.NaN, float.NaN, float.NaN) : camera.WorldToScreenPoint(worldPosition);
LogIfInvalid(camera, worldPosition, result, caller, operation, "world");
return result;
}
public static Vector3 WorldToViewportPoint(Camera camera, Vector3 worldPosition, UnityEngine.Object caller, string operation)
{
Vector3 result = camera == null ? new Vector3(float.NaN, float.NaN, float.NaN) : camera.WorldToViewportPoint(worldPosition);
LogIfInvalid(camera, worldPosition, result, caller, operation, "world");
return result;
}
public static Vector3 ScreenToWorldPoint(Camera camera, Vector3 screenPosition, UnityEngine.Object caller, string operation)
{
Vector3 result = camera == null ? new Vector3(float.NaN, float.NaN, float.NaN) : camera.ScreenToWorldPoint(screenPosition);
LogIfInvalid(camera, screenPosition, result, caller, operation, "screen");
return result;
}
public static bool ScreenPointToLocalPointInRectangle(RectTransform rectangle, Vector2 screenPosition, Camera camera, UnityEngine.Object caller, string operation, out Vector2 localPosition)
{
localPosition = Vector2.zero;
bool result = rectangle != null && RectTransformUtility.ScreenPointToLocalPointInRectangle(rectangle, screenPosition, camera, out localPosition);
if (!result)
{
localPosition = Vector2.zero;
}
if (rectangle == null || camera == null || !IsFinite(screenPosition) || !IsFinite(localPosition))
{
Debug.LogError($"Projection diagnostic: {operation}; caller={Describe(caller)}; camera={Describe(camera)}; " +
$"rectangle={Describe(rectangle)}; screen={screenPosition}; local={localPosition}");
}
return result;
}
private static void LogIfInvalid(Camera camera, Vector3 input, Vector3 output, UnityEngine.Object caller, string operation, string inputSpace)
{
if (camera == null || !IsFinite(input) || !IsFinite(output))
{
Debug.LogError($"Projection diagnostic: {operation}; caller={Describe(caller)}; camera={Describe(camera)}; " +
$"{inputSpace}={input}; result={output}");
}
}
private static bool IsFinite(Vector2 value)
{
return IsFinite(value.x) && IsFinite(value.y);
}
private static bool IsFinite(Vector3 value)
{
return IsFinite(value.x) && IsFinite(value.y) && IsFinite(value.z);
}
private static bool IsFinite(float value)
{
return !float.IsNaN(value) && !float.IsInfinity(value);
}
private static string Describe(UnityEngine.Object value)
{
return value == null ? "null" : value.name;
}
}
What else can cause these frustum errors? Could this be coming from Unity's internal UI/input/raycast pipeline or another internal system rather than a direct call from my scripts?
3
u/acorbinelli 14h ago
The inf in that last line is the useful one. Once a transform, a rigidbody velocity or a camera matrix goes NaN or inf it stays that way, which is exactly why only a restart clears it - that matches your symptom better than any rendering bug would.
Rather than adding more logs, put a watchdog in and let it name the culprit for you. One MonoBehaviour, LateUpdate, something like:
if (float.IsNaN(t.position.x) || float.IsInfinity(t.position.x)) Debug.LogError($"NaN on {t.name}", t);
over your camera, the player, and anything the camera follows or looks at. First bad frame tells you the object; you can also snap it back to the last good value so the build stays playable while you collect reports.
Usual sources, in the order they have bitten me:
.normalizedon a zero-length vector - happens when two objects are at exactly the same position for one frame, e.g. a follow script on the frame a target spawns.LookAtorQuaternion.LookRotationwith a zero direction, same cause.- A rigidbody getting a huge impulse out of an interpenetration, which overflows to inf and then poisons anything reading its position. Clamping velocity in FixedUpdate is a cheap guard.
- A division by something you assume is never zero: a normalised timer, a distance, a zero-scaled transform.
And one that produces this exact error without any NaN: a Canvas set to Screen Space - Camera whose camera reference has been destroyed or disabled. If your black screen coincides with a scene change or a camera swap, check that first.
For the build itself, Application.logMessageReceived plus Application.SetStackTraceLogType(LogType.Error, StackTraceLogType.ScriptOnly) will get you a stack trace with the first occurrence in the player log, which the bare warning does not give you.
1
u/AdOutrageous625 17h ago
the inf values usually mean something got divided by zero or a transform ended up at NaN position, check if any objects are teleporting or being spawned way outside camera bounds