Unity-Technologies/UnityCsReference · error · ArgumentNullException
clip
Error message
clip
What it means
ArgumentNullException thrown by the ClipPreviewDetails constructor when the clip parameter is null. This is the first null guard in the constructor, ensuring a valid AudioClip is provided before accessing its properties and generating a min/max overview.
Source
Thrown at Editor/Mono/Audio/StreamedAudioClipPreview.cs:64
public AudioClip clip;
public int previewPixelsToRender;
public double localStart;
public double localLength;
public bool looping;
public ClipPreviewDetails(AudioClip clip, bool isLooping, int size, double localStart, double localLength)
{
if (size < 2)
throw new ArgumentException("Size has to be larger than 1");
if (localLength <= 0)
throw new ArgumentException("length has to be longer than zero", "localLength");
if (localStart < 0)
throw new ArgumentException("localStart has to be positive", "localStart");
if (clip == null)
throw new ArgumentNullException("clip");
this.clip = clip;
preview = AudioClipMinMaxOverview.GetOverviewFor(clip);
if (preview == null)
throw new ArgumentException("Clip " + clip + "'s overview preview is null");
looping = isLooping;
this.localStart = localStart;
this.localLength = localLength;
if (looping)
{
previewPixelsToRender = size;
}
elseView on GitHub (pinned to 225b0fbdb5)
Solutions
- Null-check the clip before constructing ClipPreviewDetails.
- Skip preview rendering for elements or slots where the AudioClip is unassigned.
- Guard with: if (clip == null) return; before the constructor call.
- Ensure container elements have valid clips assigned before attempting preview rendering.
Example fix
// before var details = new ClipPreviewDetails(clip, looping, size, start, length); // after if (clip == null) return; var details = new ClipPreviewDetails(clip, looping, size, start, length);
Defensive patterns
Strategy: type-guard
Validate before calling
// Null-check clip before constructing ClipPreviewDetails if (clip == null) return; var details = new ClipPreviewDetails(clip, looping, size, localStart, localLength);
Type guard
static bool HasValidClip(AudioClip clip) => clip != null;
Prevention
- Null-check AudioClip references before preview rendering.
- Skip preview for AudioRandomContainer elements with unassigned clips.
- Guard inspector preview code with null checks on the selected clip.
- Use try-get patterns when iterating container elements to handle null clips gracefully.
When it happens
Trigger: Constructing ClipPreviewDetails with clip=null. Occurs when a preview is requested for an unassigned AudioClip slot, when a SerializedProperty referencing a clip is empty, or when a container element's audioClip field has not been set.
Common situations: AudioRandomContainer elements with no clip assigned, inspector preview rendering before a clip is dragged in, scripted operations iterating over elements where some have null clips, asset import failures leaving clip references unset.
Related errors
- Size has to be larger than 1
- length has to be longer than zero
- localStart has to be positive
- Clip {clip}'s overview preview is null
- clips
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/2de9b0a5f7d9ea05.
Report an issue: GitHub.