CoplayDev/unity-mcp · error · ArgumentException

Width must be larger than 0

Error message

Width must be larger than 0

What it means

Thrown by AudioTypePreviewGenerator.ValidateSettings when _settings.Width is zero or negative. Width defines the texture dimensions for the audio waveform preview image. This validation runs after the base class ValidateSettings (which checks InputPaths and OutputPath).

Source

Thrown at TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/TypeGenerators/AudioTypePreviewGenerator.cs:30

{
    internal class AudioTypePreviewGenerator : TypePreviewGeneratorBase
    {
        private AudioTypeGeneratorSettings _settings;
        private Texture2D _texture;

        public override event Action<int, int> OnAssetProcessed;

        public AudioTypePreviewGenerator(AudioTypeGeneratorSettings settings) : base(settings)
        {
            _settings = settings;
        }

        public override void ValidateSettings()
        {
            base.ValidateSettings();

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

            if (_settings.Height <= 0)
                throw new ArgumentException("Height must be larger than 0");
        }

        protected override IEnumerable<UnityEngine.Object> CollectAssets()
        {
            var assets = new List<UnityEngine.Object>();
            var materialGuids = AssetDatabase.FindAssets("t:audioclip", Settings.InputPaths);
            foreach (var guid in materialGuids)
            {
                var audioClip = AssetDatabase.LoadAssetAtPath<AudioClip>(AssetDatabase.GUIDToAssetPath(guid));

                // Skip nested audio clips
                if (!AssetDatabase.IsMainAsset(audioClip))
                    continue;

                // Skip materials with an error shader

View on GitHub (pinned to c21bf496bc)

Solutions

  1. Set _settings.Width to a positive integer (e.g., 512 or 1024) before calling Generate.
  2. Initialize all dimension fields when constructing AudioTypeGeneratorSettings.
  3. Validate settings at the UI layer before allowing preview generation to start.

Example fix

// before
var settings = new AudioTypeGeneratorSettings { Width = 0, Height = 256, InputPaths = paths, OutputPath = outPath };
var generator = new AudioTypePreviewGenerator(settings);
await generator.Generate();

// after
var settings = new AudioTypeGeneratorSettings { Width = 1024, Height = 256, InputPaths = paths, OutputPath = outPath };
var generator = new AudioTypePreviewGenerator(settings);
await generator.Generate();
Defensive patterns

Strategy: validation

Validate before calling

if (settings.Width <= 0)
    settings.Width = 1024; // sensible default for waveform width
// or validate before Generate():
if (settings.Width <= 0)
    throw new InvalidOperationException("Audio preview Width must be a positive value.");

Type guard

static bool IsValidAudioPreviewDimensions(AudioTypeGeneratorSettings s)
    => s.Width > 0 && s.Height > 0;

Try / catch

try
{
    await generator.Generate();
}
catch (ArgumentException ex) when (ex.Message.Contains("Width must be larger than 0"))
{
    settings.Width = 1024;
    await generator.Generate();
}

Prevention

When it happens

Trigger: Calling Generate() or ValidateSettings() on an AudioTypePreviewGenerator with _settings.Width <= 0. The width is used later to create or reinitialize a Texture2D for waveform rendering.

Common situations: Audio preview generator settings constructed without setting Width; settings deserialized from config with a missing width; UI control left at 0 for the audio preview dimension.

Related errors


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