CoplayDev/unity-mcp · error · ArgumentException

Height must be larger than 0

Error message

Height must be larger than 0

What it means

Thrown by AudioTypePreviewGenerator.ValidateSettings when _settings.Height is zero or negative. Height defines the vertical resolution of the audio waveform preview texture. Validated after Width in the override of ValidateSettings.

Source

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

        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
                if (!IsLoadTypeSupported(audioClip))
                {
                    Debug.LogWarning($"Audio clip '{audioClip}' is using a load type which cannot retrieve sample data. Preview will not be generated.");

View on GitHub (pinned to c21bf496bc)

Solutions

  1. Set _settings.Height to a positive integer (e.g., 256) before calling Generate.
  2. Set both Width and Height together when constructing AudioTypeGeneratorSettings.
  3. Apply default dimensions after deserialization if any are zero.

Example fix

// before
var settings = new AudioTypeGeneratorSettings { Width = 1024, Height = 0, InputPaths = paths, OutputPath = outPath };

// after
var settings = new AudioTypeGeneratorSettings { Width = 1024, Height = 256, InputPaths = paths, OutputPath = outPath };
Defensive patterns

Strategy: validation

Validate before calling

if (settings.Height <= 0)
    settings.Height = 256; // sensible default for waveform height
// or validate:
if (settings.Height <= 0)
    throw new InvalidOperationException("Audio preview Height 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("Height must be larger than 0"))
{
    settings.Height = 256;
    await generator.Generate();
}

Prevention

When it happens

Trigger: Calling Generate() or ValidateSettings() on an AudioTypePreviewGenerator with _settings.Height <= 0. The height parameter feeds Texture2D creation in GenerateAudioClipTexture.

Common situations: Settings constructed with Width set but Height left at default 0; deserialized config missing the height field; UI reset cleared height but not width.

Related errors


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