CoplayDev/unity-mcp · error · ArgumentException
Depth should be larger than 0
Error message
Depth should be larger than 0
What it means
Thrown by SceneScreenshotterBase.ValidateSettings when Settings.Depth is zero or negative. Depth controls the render texture depth buffer precision used when capturing the screenshot via GraphicsUtility.GetTextureFromCamera. Validation fires before texture creation.
Source
Thrown at TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/Screenshotters/SceneScreenshotterBase.cs:45
_camera = GameObject.FindFirstObjectByType<Camera>(FindObjectsInactive.Include);
#else
_camera = GameObject.FindObjectOfType<Camera>();
#endif
}
return _camera;
}
public virtual void ValidateSettings()
{
if (Settings.Width <= 0)
throw new ArgumentException("Width should be larger than 0");
if (Settings.Height <= 0)
throw new ArgumentException("Height should be larger than 0");
if (Settings.Depth <= 0)
throw new ArgumentException("Depth should be larger than 0");
if (Settings.NativeWidth <= 0)
throw new ArgumentException("Native width should be larger than 0");
if (Settings.NativeHeight <= 0)
throw new ArgumentException("Native height should be larger than 0");
}
public abstract void PositionCamera(GameObject target);
public string Screenshot(string outputPath)
{
ValidateSettings();
var texture = GraphicsUtility.GetTextureFromCamera(Camera, Settings.NativeWidth, Settings.NativeHeight, Settings.Depth);
if (Settings.Width < Settings.NativeWidth || Settings.Height < Settings.NativeHeight)
texture = GraphicsUtility.ResizeTexture(texture, Settings.Width, Settings.Height);
View on GitHub (pinned to c21bf496bc)
Solutions
- Set Settings.Depth to a standard depth buffer value (typically 16 or 24) before rendering.
- Initialize all screenshot dimension fields (Width, Height, Depth, NativeWidth, NativeHeight) together in a factory method.
- Apply post-deserialization defaults for any unset numeric fields.
Example fix
// before
var settings = new SceneScreenshotterSettings { Width = 1920, Height = 1080, Depth = 0, NativeWidth = 1920, NativeHeight = 1080 };
// after
var settings = new SceneScreenshotterSettings { Width = 1920, Height = 1080, Depth = 24, NativeWidth = 1920, NativeHeight = 1080 }; Defensive patterns
Strategy: validation
Validate before calling
if (settings.Depth <= 0)
settings.Depth = 24; // standard depth buffer
// or validate:
if (settings.Depth <= 0)
throw new InvalidOperationException("Screenshot Depth must be a positive value (typically 16 or 24)."); Type guard
static bool IsValidScreenshotDimensions(SceneScreenshotterSettings s)
=> s.Width > 0 && s.Height > 0 && s.Depth > 0 && s.NativeWidth > 0 && s.NativeHeight > 0; Try / catch
try
{
screenshotter.Screenshot(outputPath);
}
catch (ArgumentException ex) when (ex.Message.Contains("Depth should be larger than 0"))
{
settings.Depth = 24;
screenshotter.Screenshot(outputPath);
} Prevention
- Set Depth to a standard value (16 or 24) alongside Width and Height.
- Group all five dimension fields in a single initialization method.
- Apply defaults after deserialization to cover missing fields.
When it happens
Trigger: Calling Screenshot(outputPath) or ValidateSettings() with Settings.Depth <= 0. Depth is passed to GetTextureFromCamera alongside NativeWidth, NativeHeight.
Common situations: Settings object constructed without setting Depth (defaults to 0); config file missing depth field; depth field accidentally set to 0 by a UI reset.
Related errors
- Native width should be larger than 0
- Native height should be larger than 0
- Width should be larger than 0
- Height should be larger than 0
- Width must be larger than 0
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/f8abefd46f3332e3.
Report an issue: GitHub.