Unity-Technologies/UnityCsReference · error · ArgumentException
May only be called in OnPostProcessTexture
Error message
May only be called in OnPostProcessTexture
What it means
TextureImporter.DoesSourceTextureHaveAlpha reads SourceTextureInformation.containsAlpha, but like the dimensions API it is only valid once the source has been decoded. The native side reports width == -1 before that, and the method throws ArgumentException (not InvalidOperationException) with a hint that the only valid call site is OnPostProcessTexture. The misleading exception type is a known quirk of this particular guard.
Source
Thrown at Editor/Mono/AssetPipeline/TextureImporter.bindings.cs:428
internal bool IsSourceTextureHDR()
{
return GetSourceTextureInformation().hdr;
}
private extern SourceTextureInformation GetSourceTextureInformation();
[FreeFunction("IsCompressedETCTextureFormat")]
internal static extern bool IsTextureFormatETC1Compression(TextureFormat fmt);
[FreeFunction("IsBuildTargetETC")]
internal static extern bool IsETC1SupportedByBuildTarget(BuildTarget target);
// Does textures source image have alpha channel.
public bool DoesSourceTextureHaveAlpha()
{
var info = GetSourceTextureInformation();
if (info.width == -1)
throw new ArgumentException("May only be called in OnPostProcessTexture");
return info.containsAlpha;
}
// Does textures source image have RGB channels.
[System.Obsolete("DoesSourceTextureHaveColor always returns true in Unity.")]
public bool DoesSourceTextureHaveColor()
{
return true;
}
// Which type of texture are we dealing with here
public extern TextureImporterType textureType { get; set; }
public extern TextureImporterShape textureShape { get; set; }
// Read texture settings into [[TextureImporterSettings]] class.
public void ReadTextureSettings(TextureImporterSettings dest)
{View on GitHub (pinned to 225b0fbdb5)
Solutions
- Call DoesSourceTextureHaveAlpha only from AssetPostprocessor.OnPostprocessTexture (or after import finishes).
- In pre-import hooks, derive alpha expectations from the importer settings or format instead of the source image.
- If you need source alpha earlier, decode the file yourself or restructure so the decision is made post-import.
Example fix
// before (pre-import)
bool alpha = importer.DoesSourceTextureHaveAlpha();
// after (post-import hook)
public void OnPostprocessTexture(Texture2D tex) {
bool alpha = tex.format == TextureFormat.Alpha8 || /* ... */;
// or call importer.DoesSourceTextureHaveAlpha() here, where it is valid
} Defensive patterns
Strategy: validation
Validate before calling
// Only valid inside OnPostprocessTexture.
public void OnPostprocessTexture(Texture2D tex) {
bool alpha = (tex.format == TextureFormat.Alpha8) || /* format check */;
// use 'alpha' instead of importer.DoesSourceTextureHaveAlpha()
} Try / catch
try {
bool alpha = importer.DoesSourceTextureHaveAlpha();
} catch (System.ArgumentException) {
// not yet decoded; defer to OnPostprocessTexture
} Prevention
- Reserve DoesSourceTextureHaveAlpha for OnPostprocessTexture.
- Make alpha-dependent decisions from importer settings or the decoded Texture2D.
- Document which importer queries are valid at each pipeline hook.
When it happens
Trigger: Calling DoesSourceTextureHaveAlpha from OnPreprocessAsset or any code path before the texture is decoded; calling on an importer that has not finished importing.
Common situations: Pre-import logic trying to pick alpha-handling settings from source alpha; editor scripts querying alpha outside the postprocess hook.
Related errors
- The texture has not yet finished importing. This most likely
- path
- paths
- The name is empty
- Invalid material folder path: {0}.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/b814dea019875a32.
Report an issue: GitHub.