CoplayDev/unity-mcp · error · ArgumentException
Height should be larger than 0
Error message
Height should be larger than 0
What it means
Thrown by CustomPreviewGenerator.Validate() (CustomPreviewGenerator.cs:33) when CustomPreviewGenerationSettings.Height <= 0. Height is the vertical output render resolution, propagated into SceneScreenshotterSettings.Height and TextureTypeGeneratorSettings.MaxHeight. Zero/negative height yields an invalid RenderTexture. Like the other dimension checks it runs before GenerateImpl() and is not caught by its try/catch, so it surfaces as an uncaught ArgumentException.
Source
Thrown at TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/CustomPreviewGenerator.cs:33
private CustomPreviewGenerationSettings _customSettings;
public override event Action<float> OnProgressChanged;
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
};
View on GitHub (pinned to c21bf496bc)
Solutions
- Set CustomPreviewGenerationSettings.Height to a positive value (e.g. 128) before Generate().
- Populate all dimension fields (Width, Height, Depth, NativeWidth, NativeHeight) together at construction.
- Verify the height field in the Preview Generator window is non-empty before generating.
Example fix
// before
var settings = new CustomPreviewGenerationSettings { Width = 256, /* Height missing */ };
await new CustomPreviewGenerator(settings).Generate(); // throws
// after
var settings = new CustomPreviewGenerationSettings { Width = 256, Height = 128 };
await new CustomPreviewGenerator(settings).Generate(); Defensive patterns
Strategy: validation
Validate before calling
var s = settings as CustomPreviewGenerationSettings;
if (s != null && s.Height <= 0)
throw new InvalidOperationException("CustomPreviewGenerationSettings.Height must be > 0 before generating previews."); Type guard
static bool HasValidHeight(CustomPreviewGenerationSettings s) => s != null && s.Height > 0;
Try / catch
try { await generator.Generate(); }
catch (ArgumentException ex) when (ex.Message.Contains("Height")) { /* report invalid height */ } Prevention
- Validate Height together with Width in the same pre-flight check.
- Never partial-initialize the dimension fields.
When it happens
Trigger: Calling Generate() with Height unset (default 0) or set <= 0 on a CustomPreviewGenerationSettings. Same lifecycle as the Width check: a settings object built without assigning Height, or a UI submit with an empty height field.
Common situations: Object-initializer that sets Width but omits Height; refactoring that renamed or removed the Height assignment; default-int-zero slipping through a code path that bypasses the window's own clamping.
Related errors
- Width should be larger than 0
- Depth should be larger than 0
- Native width should be larger than 0
- Native height should be larger than 0
- Chunk size must be larger than 0
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/248261d10f4e2ad7.
Report an issue: GitHub.