CoplayDev/unity-mcp · error · ArgumentException

Native height should be larger than 0

Error message

Native height should be larger than 0

What it means

Thrown by SceneScreenshotterBase.ValidateSettings when Settings.NativeHeight is zero or negative. NativeHeight is the vertical render resolution for GetTextureFromCamera, checked after NativeWidth. The screenshot pipeline renders at native dimensions then optionally resizes down to Width/Height.

Source

Thrown at TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/Screenshotters/SceneScreenshotterBase.cs:51

            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);

            var extension = PreviewConvertUtility.ConvertExtension(Settings.Format);
            var writtenPath = $"{outputPath}.{extension}";
            var bytes = PreviewConvertUtility.ConvertTexture(texture, Settings.Format);
            File.WriteAllBytes(writtenPath, bytes);

View on GitHub (pinned to c21bf496bc)

Solutions

  1. Set Settings.NativeHeight to a positive integer before calling Screenshot.
  2. Construct settings via a factory that guarantees all five dimension fields are populated.
  3. After deserialization, default NativeHeight to Height if it is still zero.

Example fix

// before
var settings = new SceneScreenshotterSettings { Width = 1024, Height = 1024, Depth = 24, NativeWidth = 2048, NativeHeight = 0 };

// after
var settings = new SceneScreenshotterSettings { Width = 1024, Height = 1024, Depth = 24, NativeWidth = 2048, NativeHeight = 2048 };
Defensive patterns

Strategy: validation

Validate before calling

if (settings.NativeHeight <= 0)
    settings.NativeHeight = settings.Height > 0 ? settings.Height : 1080;
// or validate:
if (settings.NativeHeight <= 0)
    throw new InvalidOperationException("NativeHeight 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("Native height should be larger than 0"))
{
    settings.NativeHeight = settings.Height;
    screenshotter.Screenshot(outputPath);
}

Prevention

When it happens

Trigger: Calling Screenshot(outputPath) or ValidateSettings() with Settings.NativeHeight <= 0. NativeHeight feeds GraphicsUtility.GetTextureFromCamera.

Common situations: Settings partially initialized — Width, Height, NativeWidth set but NativeHeight left at default; config deserialization missing this field; settings cloned from another object where NativeHeight was cleared.

Related errors


AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13). Data as JSON: /api/errors/8075e682728d7693. Report an issue: GitHub.