{"record":{"id":"2f1ba713852fca3d","repo":"Unity-Technologies/UnityCsReference","slug":"the-texture-has-not-yet-finished-importing-this-m","errorCode":null,"errorMessage":"The texture has not yet finished importing. This most likely means this method was called in an AssetPostprocessor.OnPreprocessAsset callback.","messagePattern":"The texture has not yet finished importing\\. This most likely means this method was called in an AssetPostprocessor\\.OnPreprocessAsset callback\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetPipeline/TextureImporter.bindings.cs","lineNumber":404,"sourceCode":"\n        [System.Obsolete(\"Use spritePixelsPerUnit property instead.\")]\n        public extern float spritePixelsToUnits { get; set; }\n\n        public extern Vector2 spritePivot { get; set; }\n        public extern Vector4 spriteBorder { get; set; }\n\n        internal void GetWidthAndHeight(ref int width, ref int height)\n        {\n            var info = GetSourceTextureInformation();\n            width = info.width;\n            height = info.height;\n        }\n\n        public void GetSourceTextureWidthAndHeight(out int width, out int height)\n        {\n            var info = GetSourceTextureInformation();\n            if (info.width == -1)\n                throw new InvalidOperationException(\"The texture has not yet finished importing. This most likely means this method was called in an AssetPostprocessor.OnPreprocessAsset callback.\");\n\n            width = info.width;\n            height = info.height;\n        }\n\n        internal bool IsSourceTextureHDR()\n        {\n            return GetSourceTextureInformation().hdr;\n        }\n\n        private extern SourceTextureInformation GetSourceTextureInformation();\n\n        [FreeFunction(\"IsCompressedETCTextureFormat\")]\n        internal static extern  bool IsTextureFormatETC1Compression(TextureFormat fmt);\n\n        [FreeFunction(\"IsBuildTargetETC\")]\n        internal static extern  bool IsETC1SupportedByBuildTarget(BuildTarget target);\n","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetPipeline/TextureImporter.bindings.cs#L386-L422","documentation":"TextureImporter.GetSourceTextureWidthAndHeight returns the source image dimensions, but the native SourceTextureInformation is populated lazily during import and reports width == -1 until the texture has actually been decoded. Calling before that point throws InvalidOperationException to prevent callers from acting on the -1 sentinel. The message names the most common cause: invoking it inside AssetPostprocessor.OnPreprocessAsset, which runs before the image is read.","triggerScenarios":"Calling GetSourceTextureWidthAndHeight inside OnPreprocessAsset; calling on a freshly created/modified importer whose import has not yet run; calling synchronously right after SetSourceTextureInformation changes without re-importing.","commonSituations":"Trying to read source dimensions to decide compression settings during pre-import; invoking importer methods from a different pipeline hook than intended; editor scripts that touch the importer outside the import flow.","solutions":["Move the call to a hook that runs after the image is decoded, e.g. AssetPostprocessor.OnPostprocessTexture, or call it after AssetDatabase.ImportAsset completes.","Guard with info.width == -1 detection by first reading via the same condition the API uses, or use an API valid at your pipeline stage.","If you only need dimensions for settings logic, defer that logic to post-import and cache the result."],"exampleFix":"// before (inside OnPreprocessAsset)\nimporter.GetSourceTextureWidthAndHeight(out int w, out int h);\n\n// after (defer to post-import hook)\npublic void OnPostprocessTexture(Texture2D tex) {\n    int w = tex.width, h = tex.height; // already decoded\n    // ...use dimensions here\n}","handlingStrategy":"validation","validationCode":"// Only valid after the source has been decoded.\npublic void OnPostprocessTexture(Texture2D tex) {\n    int w = tex.width, h = tex.height;\n    // use dimensions here instead of GetSourceTextureWidthAndHeight\n}","typeGuard":null,"tryCatchPattern":"try {\n    importer.GetSourceTextureWidthAndHeight(out int w, out int h);\n} catch (System.InvalidOperationException) {\n    // texture not decoded yet; defer to OnPostprocessTexture\n}","preventionTips":["Do not call dimension APIs in OnPreprocessAsset; defer to OnPostprocessTexture.","If you must decide pre-import, derive settings from importer configuration, not source pixels.","Re-import (AssetDatabase.ImportAsset) and only then query dimensions synchronously."],"tags":["unity","texture-importer","pipeline-timing","invalid-operation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}