CoplayDev/unity-mcp · error · ArgumentException

Depth should be larger than 0

Error message

Depth should be larger than 0

What it means

Thrown by CustomPreviewGenerator.Validate() (CustomPreviewGenerator.cs:36) when CustomPreviewGenerationSettings.Depth <= 0. Depth is the render depth used by SceneScreenshotterSettings.Depth for material/model/prefab screenshots (camera depth/orthographic sizing). Zero or negative depth would make the screenshot scene setup invalid. Thrown before GenerateImpl(), outside its try/catch, so it propagates as an uncaught ArgumentException.

Source

Thrown at TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/CustomPreviewGenerator.cs:36

        public CustomPreviewGenerator(CustomPreviewGenerationSettings settings)
            : base(settings)
        {
            _customSettings = settings;
        }

        protected override void Validate()
        {
            base.Validate();

            if (_customSettings.Width <= 0)
                throw new ArgumentException("Width should be larger than 0");

            if (_customSettings.Height <= 0)
                throw new ArgumentException("Height should be larger than 0");

            if (_customSettings.Depth <= 0)
                throw new ArgumentException("Depth should be larger than 0");

            if (_customSettings.NativeWidth <= 0)
                throw new ArgumentException("Native width should be larger than 0");

            if (_customSettings.NativeHeight <= 0)
                throw new ArgumentException("Native height should be larger than 0");
        }

        protected override async Task<PreviewGenerationResult> GenerateImpl()
        {
            var result = new PreviewGenerationResult()
            {
                GenerationType = _customSettings.GenerationType
            };

            OnProgressChanged?.Invoke(0f);

            var generatedPreviews = new List<PreviewMetadata>();

View on GitHub (pinned to c21bf496bc)

Solutions

  1. Set CustomPreviewGenerationSettings.Depth to a positive value (e.g. 100) before Generate().
  2. Always populate Width, Height, Depth, NativeWidth, NativeHeight together when building custom settings.
  3. Confirm the Depth field in the Preview Generator window before generating.

Example fix

// before
var settings = new CustomPreviewGenerationSettings { Width = 256, Height = 128 /* Depth missing */ };
await new CustomPreviewGenerator(settings).Generate(); // throws

// after
var settings = new CustomPreviewGenerationSettings { Width = 256, Height = 128, Depth = 100 };
await new CustomPreviewGenerator(settings).Generate();
Defensive patterns

Strategy: validation

Validate before calling

var s = settings as CustomPreviewGenerationSettings;
if (s != null && s.Depth <= 0)
    throw new InvalidOperationException("CustomPreviewGenerationSettings.Depth must be > 0 before generating previews.");

Type guard

static bool HasValidDepth(CustomPreviewGenerationSettings s) => s != null && s.Depth > 0;

Try / catch

try { await generator.Generate(); }
catch (ArgumentException ex) when (ex.Message.Contains("Depth")) { /* report invalid depth */ }

Prevention

When it happens

Trigger: Generate() is called on settings where Depth was left at its default 0 or set negative. Happens when constructing CustomPreviewGenerationSettings without Depth, or when only texture/audio previews are intended but the shared Depth field is still required.

Common situations: Settings initializer that sets Width/Height but forgets Depth; assumption that Depth only matters for 3D screenshots and can be skipped (it cannot — Validate() always checks it).

Related errors


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