CoplayDev/unity-mcp · error · ArgumentException
Max width should be larger than 0
Error message
Max width should be larger than 0
What it means
Thrown by TextureTypePreviewGenerator.ValidateSettings when _settings.MaxWidth is zero or negative. MaxWidth caps the output size of texture previews — source textures larger than MaxWidth are downscaled. Validation runs after the base class check of InputPaths and OutputPath.
Source
Thrown at TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/TypeGenerators/TextureTypePreviewGenerator.cs:29
namespace AssetStoreTools.Previews.Generators.Custom.TypeGenerators
{
internal class TextureTypePreviewGenerator : TypePreviewGeneratorBase
{
private TextureTypeGeneratorSettings _settings;
public override event Action<int, int> OnAssetProcessed;
public TextureTypePreviewGenerator(TextureTypeGeneratorSettings settings) : base(settings)
{
_settings = settings;
}
public override void ValidateSettings()
{
base.ValidateSettings();
if (_settings.MaxWidth <= 0)
throw new ArgumentException("Max width should be larger than 0");
if (_settings.MaxHeight <= 0)
throw new ArgumentException("Max height should be larger than 0");
}
protected override IEnumerable<UnityEngine.Object> CollectAssets()
{
var textures = new List<UnityEngine.Object>();
var textureGuids = AssetDatabase.FindAssets("t:texture", Settings.InputPaths);
foreach (var guid in textureGuids)
{
var texture = AssetDatabase.LoadAssetAtPath<Texture>(AssetDatabase.GUIDToAssetPath(guid));
// Skip nested textures
if (!AssetDatabase.IsMainAsset(texture))
continue;
View on GitHub (pinned to c21bf496bc)
Solutions
- Set _settings.MaxWidth to a positive integer (e.g., 512 or 1024) before calling Generate.
- Initialize MaxWidth and MaxHeight together when constructing TextureTypeGeneratorSettings.
- Apply sensible defaults after deserialization.
Example fix
// before
var settings = new TextureTypeGeneratorSettings { MaxWidth = 0, MaxHeight = 512, InputPaths = paths, OutputPath = outPath };
// after
var settings = new TextureTypeGeneratorSettings { MaxWidth = 1024, MaxHeight = 1024, InputPaths = paths, OutputPath = outPath }; Defensive patterns
Strategy: validation
Validate before calling
if (settings.MaxWidth <= 0)
settings.MaxWidth = 1024; // sensible default
// or validate:
if (settings.MaxWidth <= 0)
throw new InvalidOperationException("Texture preview MaxWidth must be a positive value."); Type guard
static bool IsValidTexturePreviewDimensions(TextureTypeGeneratorSettings s)
=> s.MaxWidth > 0 && s.MaxHeight > 0; Try / catch
try
{
await generator.Generate();
}
catch (ArgumentException ex) when (ex.Message.Contains("Max width should be larger than 0"))
{
settings.MaxWidth = 1024;
await generator.Generate();
} Prevention
- Set MaxWidth and MaxHeight together when constructing texture preview settings.
- Clamp UI inputs to a minimum of 1 for max dimension fields.
- Apply defaults after deserialization.
When it happens
Trigger: Calling Generate() or ValidateSettings() on a TextureTypePreviewGenerator with _settings.MaxWidth <= 0. MaxWidth is used during texture resize operations in the generation pipeline.
Common situations: Texture preview settings constructed without MaxWidth; settings deserialized from config with a missing field; UI control set to 0 or left at default.
Related errors
- Max height should be larger than 0
- 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
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/682a8f17cdda96b9.
Report an issue: GitHub.