{"record":{"id":"c199d7f26c7b19c2","repo":"CoplayDev/unity-mcp","slug":"could-not-retrieve-guid-for-object-obj","errorCode":null,"errorMessage":"Could not retrieve guid for object {obj}","messagePattern":"Could not retrieve guid for object (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/TypeGenerators/TypePreviewGeneratorBase.cs","lineNumber":80,"sourceCode":"            {\r\n                if (!AssetDatabase.TryGetGUIDAndLocalFileIdentifier(asset, out var guid, out long _))\r\n                    continue;\r\n\r\n                if (Settings.IgnoredGuids.Any(x => x == guid))\r\n                    continue;\r\n\r\n                filteredAssets.Add(asset);\r\n            }\r\n\r\n            return filteredAssets;\r\n        }\r\n\r\n        protected abstract Task<List<PreviewMetadata>> GenerateImpl(IEnumerable<UnityEngine.Object> assets);\r\n\r\n        protected PreviewMetadata ObjectToMetadata(UnityEngine.Object obj, string previewPath)\r\n        {\r\n            if (!AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out var guid, out long _))\r\n                throw new Exception($\"Could not retrieve guid for object {obj}\");\r\n\r\n            return new PreviewMetadata()\r\n            {\r\n                Type = GenerationType.Custom,\r\n                Guid = guid,\r\n                Name = obj.name,\r\n                Path = previewPath\r\n            };\r\n        }\r\n\r\n        protected string GenerateOutputPathWithoutExtension(UnityEngine.Object asset, FileNameFormat fileNameFormat)\r\n        {\r\n            PrepareOutputFolder(Settings.OutputPath, false);\r\n            var directoryPath = Settings.OutputPath;\r\n            var fileName = PreviewConvertUtility.ConvertFilename(asset, fileNameFormat);\r\n            var fullPath = $\"{directoryPath}/{fileName}\";\r\n\r\n            return fullPath;\r","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Previews/Scripts/Generators/Custom/TypeGenerators/TypePreviewGeneratorBase.cs#L62-L98","documentation":"Thrown by TypePreviewGeneratorBase.ObjectToMetadata when AssetDatabase.TryGetGUIDAndLocalFileIdentifier fails to resolve a GUID for a given UnityEngine.Object. The GUID is needed to construct PreviewMetadata. Failure indicates the object is not a persistent asset tracked by the AssetDatabase — it may be a scene instance, a runtime-created object, or an object whose .meta file is missing.","triggerScenarios":"Calling ObjectToMetadata(obj, previewPath) where obj is not a persistent AssetDatabase asset. TryGetGUIDAndLocalFileIdentifier returns false.","commonSituations":"CollectAssets returned a non-persistent object (e.g., a material instance created at runtime); asset's .meta file was deleted; asset was moved and the GUID is stale; object is a sub-asset or embedded resource not directly addressable by GUID.","solutions":["Filter out non-persistent objects in CollectAssets before passing them to ObjectToMetadata.","Verify AssetDatabase.Contains(obj) returns true before calling ObjectToMetadata.","Run AssetDatabase.Refresh() if .meta files may be out of sync.","Log the object's type and name when GUID resolution fails instead of throwing, to allow batch processing to continue."],"exampleFix":"// before\nprotected PreviewMetadata ObjectToMetadata(UnityEngine.Object obj, string previewPath)\n{\n    if (!AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out var guid, out long _))\n        throw new Exception($\"Could not retrieve guid for object {obj}\");\n    ...\n}\n\n// after\nprotected PreviewMetadata ObjectToMetadata(UnityEngine.Object obj, string previewPath)\n{\n    if (!AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out var guid, out long _))\n        throw new Exception($\"Could not retrieve guid for object '{obj.name}' ({obj.GetType()}). Ensure it is a persistent AssetDatabase asset.\");\n    ...\n}","handlingStrategy":"validation","validationCode":"// Filter to persistent assets only before generating metadata\nvar persistentAssets = assets.Where(a => AssetDatabase.Contains(a)).ToList();\nif (persistentAssets.Count < assets.Count())\n    Debug.LogWarning($\"Filtered out {assets.Count() - persistentAssets.Count} non-persistent objects.\");","typeGuard":"static bool IsPersistentAsset(UnityEngine.Object obj)\n    => obj != null && AssetDatabase.Contains(obj) &&\n       AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out _, out _);","tryCatchPattern":"try\n{\n    var metadata = ObjectToMetadata(obj, previewPath);\n}\ncatch (Exception ex) when (ex.Message.Contains(\"Could not retrieve guid\"))\n{\n    ASDebug.LogWarning($\"Skipping {obj.name}: not a persistent AssetDatabase asset.\");\n    continue;\n}","preventionTips":["Filter CollectAssets results to only persistent assets via AssetDatabase.Contains.","Run AssetDatabase.Refresh() if .meta files may be out of sync.","Log object type and name when GUID resolution fails to aid debugging.","Handle non-persistent objects gracefully instead of aborting the batch."],"tags":["unity","asset-store-tools","preview","asset-database","guid"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}