CoplayDev/unity-mcp · error · ArgumentException
Width should be larger than 0
Error message
Width should be larger than 0
What it means
Thrown by CustomPreviewGenerator.Validate() (CustomPreviewGenerator.cs:30) when CustomPreviewGenerationSettings.Width <= 0. Width is the output render resolution: it is propagated into SceneScreenshotterSettings.Width (material/model/prefab screenshots) and TextureTypeGeneratorSettings.MaxWidth. A zero or negative value would produce an invalid RenderTexture. Validate() runs inside Generate() before GenerateImpl() and outside its try/catch, so the ArgumentException propagates uncaught to the caller (typically the Preview Generator window).
Source
Thrown at TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/CustomPreviewGenerator.cs:30
{
internal class CustomPreviewGenerator : PreviewGeneratorBase
{
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()
{
View on GitHub (pinned to c21bf496bc)
Solutions
- Set CustomPreviewGenerationSettings.Width to a positive value (e.g. 128 or 256) before calling Generate().
- When building settings programmatically, populate all five dimension fields together (Width, Height, Depth, NativeWidth, NativeHeight) right after construction.
- In the Preview Generator window, confirm the Width field holds a positive number before clicking Generate.
Example fix
// before
var settings = new CustomPreviewGenerationSettings {
InputPaths = paths, OutputPath = outPath,
Height = 128, Depth = 100, NativeWidth = 1024, NativeHeight = 1024
};
await new CustomPreviewGenerator(settings).Generate(); // throws
// after
var settings = new CustomPreviewGenerationSettings {
InputPaths = paths, OutputPath = outPath,
Width = 256, Height = 128, Depth = 100, NativeWidth = 1024, NativeHeight = 1024
};
await new CustomPreviewGenerator(settings).Generate(); Defensive patterns
Strategy: validation
Validate before calling
// C# - check before Generate()
var s = settings as CustomPreviewGenerationSettings;
if (s != null && s.Width <= 0)
throw new InvalidOperationException("CustomPreviewGenerationSettings.Width must be > 0 before generating previews."); Type guard
static bool HasValidWidth(CustomPreviewGenerationSettings s) => s != null && s.Width > 0;
Try / catch
try { await generator.Generate(); }
catch (ArgumentException ex) when (ex.Message.Contains("Width")) { /* report invalid width, fix settings */ } Prevention
- Centralize CustomPreviewGenerationSettings construction in one factory that asserts all five dimensions are positive.
- Add a UI clamp so the Preview Generator window cannot submit a non-positive width.
When it happens
Trigger: Calling generator.Generate() on a CustomPreviewGenerator built from a CustomPreviewGenerationSettings whose Width field was never assigned (default int = 0), or was explicitly set to 0 or a negative number. Occurs when settings are constructed programmatically without setting Width, or when the Preview Generator window submits while the width field is empty.
Common situations: Default-initializing a settings object with `new CustomPreviewGenerationSettings()` and forgetting Width (all int fields default to 0); a UI/code path that clears dimensions before validation; migration from an older settings shape that lacked Width.
Related errors
- Height 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/46a09ab87473e7cb.
Report an issue: GitHub.