CoplayDev/unity-mcp · error · Exception
Could not load audio data
Error message
Could not load audio data
What it means
Thrown when AudioClip.LoadAudioData() returns false during audio waveform texture generation. LoadAudioData attempts to load the compressed audio data into memory for sample access. Failure means the clip's data could not be decoded — the clip may be corrupted, streaming-type without data on disk, or not yet imported.
Source
Thrown at TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/TypeGenerators/AudioTypePreviewGenerator.cs:96
var texture = GenerateAudioClipTexture(audioClip);
var outputPath = GenerateOutputPathWithExtension(audioClip, _settings.PreviewFileNamingFormat, _settings.Format);
var bytes = PreviewConvertUtility.ConvertTexture(texture, _settings.Format);
File.WriteAllBytes(outputPath, bytes);
generatedPreviews.Add(ObjectToMetadata(audioClip, outputPath));
}
OnAssetProcessed?.Invoke(i, audioClips.Count);
await Task.Yield();
}
return generatedPreviews;
}
private Texture2D GenerateAudioClipTexture(AudioClip audioClip)
{
if (!audioClip.LoadAudioData())
throw new Exception("Could not load audio data");
try
{
if (_texture == null)
_texture = new Texture2D(_settings.Width, _settings.Height);
else
#if UNITY_2021_3_OR_NEWER || UNITY_2022_1_OR_NEWER || UNITY_2021_2_OR_NEWER
_texture.Reinitialize(_settings.Width, _settings.Height);
#else
_texture.Resize(_settings.Width, _settings.Height);
#endif
FillTextureBackground();
FillTextureForeground(audioClip);
_texture.Apply();
return _texture;
}
View on GitHub (pinned to c21bf496bc)
Solutions
- Reimport the audio asset in Unity (right-click > Reimport) to ensure data is decoded.
- Check that the audio file on disk is valid and not corrupted.
- Ensure the AudioClip import settings have 'Preload Audio Data' enabled or wait for load completion before generating previews.
- Filter out clips where LoadAudioData fails and log them as skipped rather than aborting the entire batch.
Example fix
// before
if (!audioClip.LoadAudioData())
throw new Exception("Could not load audio data");
// after
if (!audioClip.LoadAudioData())
{
ASDebug.LogWarning($"Skipping {audioClip.name}: audio data could not be loaded.");
continue;
} Defensive patterns
Strategy: try-catch
Validate before calling
// Check loadability before generating preview
if (!audioClip.LoadAudioData())
{
Debug.LogWarning($"Skipping preview for {audioClip.name}: cannot load audio data.");
continue;
}
// Optionally wait for load completion
while (audioClip.loadState == AudioDataLoadState.Loading)
await Task.Yield(); Type guard
static bool CanLoadAudioData(AudioClip clip)
{
if (clip == null) return false;
// Check if the clip is backed by a valid asset path
var path = AssetDatabase.GetAssetPath(clip);
return !string.IsNullOrEmpty(path) && File.Exists(path);
} Try / catch
try
{
var texture = GenerateAudioClipTexture(audioClip);
}
catch (Exception ex) when (ex.Message.Contains("Could not load audio data"))
{
ASDebug.LogWarning($"Skipping {audioClip.name}: audio data unavailable. Reimport may be needed.");
continue; // skip this clip, continue batch
} Prevention
- Enable 'Preload Audio Data' in the AudioClip import settings for preview assets.
- Reimport audio assets before batch preview generation.
- Filter out streaming or runtime-generated clips that lack persistent data.
- Check audioClip.loadState before attempting sample access.
When it happens
Trigger: Calling GenerateAudioClipTexture(audioClip) where audioClip.LoadAudioData() returns false. This occurs inside the per-asset preview generation loop in AudioTypePreviewGenerator.
Common situations: Audio clip is a streaming-compressed format whose underlying file was moved or deleted; clip import failed silently; clip is a synthesized/runtime AudioClip not backed by an asset file; audio file is corrupted; the clip's preload setting is disabled and background loading hasn't completed.
Related errors
- Could not retrieve audio samples
- Width must be larger than 0
- Height must be larger than 0
- Width should be larger than 0
- Height should be larger than 0
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/32ec0662abcdb446.
Report an issue: GitHub.