CoplayDev/unity-mcp · error · ArgumentException
Height should be larger than 0
Error message
Height should be larger than 0
What it means
Thrown by SceneScreenshotterBase.ValidateSettings when Settings.Height is zero or negative. Height dimensions the output screenshot texture vertically. Validation fires synchronously before camera rendering in Screenshot().
Solutions
- Set Settings.Height to a positive integer (e.g., 1080) before calling Screenshot.
- Apply default dimensions after deserializing settings from disk.
- Clamp height at the UI layer to a minimum of 1.
Example fix
// before
var settings = new SceneScreenshotterSettings { Width = 1920, Height = 0, ... };
screenshotter.Screenshot(outputPath);
// after
var settings = new SceneScreenshotterSettings { Width = 1920, Height = 1080, ... };
screenshotter.Screenshot(outputPath); Defensive patterns
Strategy: validation
Validate before calling
if (settings.Height <= 0)
settings.Height = 1080; // apply default
// or validate before calling Screenshot:
if (settings.Height <= 0)
throw new InvalidOperationException("Screenshot Height must be set to a positive value."); 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("Height should be larger than 0"))
{
settings.Height = 1080;
screenshotter.Screenshot(outputPath);
} Prevention
- Set Height alongside Width in the same initialization block.
- Use a settings factory that guarantees all dimensions are positive.
- Validate dimension fields after any deserialization or reset operation.
When it happens
Trigger: Calling Screenshot(outputPath) or ValidateSettings() on a SceneScreenshotterBase subclass with Settings.Height <= 0.
Common situations: Settings deserialized with missing height; UI control left at default 0; programmatic caller forgot to set Height after constructing settings.
Related errors
- Screenshotter cannot be null
- Width should be larger than 0
- Depth should be larger than 0
- Height must be larger than 0
- Input path cannot be null
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/ed41d7ed79cbce65.
Report an issue: GitHub.
Appendix: source
Thrown at TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/Screenshotters/SceneScreenshotterBase.cs:42
if (_camera == null)
{
#if UNITY_2022_3_OR_NEWER
_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);
View on GitHub (pinned to c21bf496bc)