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 CustomPreviewGenerator.Validate() (CustomPreviewGenerator.cs:42) when CustomPreviewGenerationSettings.NativeHeight <= 0. NativeHeight is the native offscreen render height (pre-downscale) passed to SceneScreenshotterSettings.NativeHeight. Non-positive makes the render target invalid. It is the last of the five dimension checks; thrown before GenerateImpl() and 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:42
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>();
var existingPreviews = GetExistingPreviews();
var generators = CreateGenerators(existingPreviews);
var currentGenerator = 0;
Action<int, int> generatorProgressCallback = null;
generatorProgressCallback = (currentAsset, totalAssets) => ReportProgress(currentGenerator, generators.Count(), currentAsset, totalAssets);
View on GitHub (pinned to c21bf496bc)
Solutions
- Set CustomPreviewGenerationSettings.NativeHeight to a positive value (e.g. 1024) before Generate().
- Always set NativeWidth and NativeHeight as a pair alongside Width/Height/Depth.
- Verify the Native Height field in the Preview Generator window before generating.
Example fix
// before
var settings = new CustomPreviewGenerationSettings { Width = 256, Height = 128, Depth = 100, NativeWidth = 1024 /* NativeHeight missing */ };
await new CustomPreviewGenerator(settings).Generate(); // throws
// after
var settings = new CustomPreviewGenerationSettings { Width = 256, Height = 128, Depth = 100, NativeWidth = 1024, NativeHeight = 1024 };
await new CustomPreviewGenerator(settings).Generate(); Defensive patterns
Strategy: validation
Validate before calling
var s = settings as CustomPreviewGenerationSettings;
if (s != null && s.NativeHeight <= 0)
throw new InvalidOperationException("CustomPreviewGenerationSettings.NativeHeight must be > 0 before generating previews."); Type guard
static bool HasValidNativeHeight(CustomPreviewGenerationSettings s) => s != null && s.NativeHeight > 0;
Try / catch
try { await generator.Generate(); }
catch (ArgumentException ex) when (ex.Message.Contains("Native height")) { /* report invalid native height */ } Prevention
- Set NativeWidth and NativeHeight together to avoid the partial-pair mistake.
- Add a single assertion covering all five dimension fields before Generate().
When it happens
Trigger: Generate() called with NativeHeight unset (default 0) or <= 0. Occurs when the native-resolution pair is partially set (NativeWidth set, NativeHeight forgotten) or both omitted.
Common situations: Initializer that sets NativeWidth but not NativeHeight; copy-paste error leaving one native field at default; settings deserialization that dropped NativeHeight.
Related errors
- Width should be larger than 0
- Height should be larger than 0
- Depth should be larger than 0
- Native width 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/f582478bd3c0dc5d.
Report an issue: GitHub.