{"record":{"id":"3b765ab2f0a3d2e7","repo":"EllanJiang/GameFramework","slug":"can-not-load-asset-0","errorCode":null,"errorMessage":"Can not load asset '{0}'.","messagePattern":"Can not load asset '(.+?)'\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.ResourceLoader.cs","lineNumber":319,"sourceCode":"            /// <param name=\"assetName\">要加载资源的名称。</param>\n            /// <param name=\"assetType\">要加载资源的类型。</param>\n            /// <param name=\"priority\">加载资源的优先级。</param>\n            /// <param name=\"loadAssetCallbacks\">加载资源回调函数集。</param>\n            /// <param name=\"userData\">用户自定义数据。</param>\n            public void LoadAsset(string assetName, Type assetType, int priority, LoadAssetCallbacks loadAssetCallbacks, object userData)\n            {\n                ResourceInfo resourceInfo = null;\n                string[] dependencyAssetNames = null;\n                if (!CheckAsset(assetName, out resourceInfo, out dependencyAssetNames))\n                {\n                    string errorMessage = Utility.Text.Format(\"Can not load asset '{0}'.\", assetName);\n                    if (loadAssetCallbacks.LoadAssetFailureCallback != null)\n                    {\n                        loadAssetCallbacks.LoadAssetFailureCallback(assetName, resourceInfo != null && !resourceInfo.Ready ? LoadResourceStatus.NotReady : LoadResourceStatus.NotExist, errorMessage, userData);\n                        return;\n                    }\n\n                    throw new GameFrameworkException(errorMessage);\n                }\n\n                if (resourceInfo.IsLoadFromBinary)\n                {\n                    string errorMessage = Utility.Text.Format(\"Can not load asset '{0}' which is a binary asset.\", assetName);\n                    if (loadAssetCallbacks.LoadAssetFailureCallback != null)\n                    {\n                        loadAssetCallbacks.LoadAssetFailureCallback(assetName, LoadResourceStatus.TypeError, errorMessage, userData);\n                        return;\n                    }\n\n                    throw new GameFrameworkException(errorMessage);\n                }\n\n                LoadAssetTask mainTask = LoadAssetTask.Create(assetName, assetType, priority, resourceInfo, dependencyAssetNames, loadAssetCallbacks, userData);\n                foreach (string dependencyAssetName in dependencyAssetNames)\n                {\n                    if (!LoadDependencyAsset(dependencyAssetName, priority, mainTask, userData))","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.ResourceLoader.cs#L301-L337","documentation":"LoadAsset could not resolve or load the requested asset and no failure callback was supplied, so the error message is thrown instead. It fires when the asset is missing from asset info, not ready, or the resource it maps to failed checks.","triggerScenarios":"Calling LoadAsset with an asset name that has no entry in the asset info table, whose resource is not ready, or — as shown — when resourceInfo indicates failure and LoadAssetFailureCallback is null, so the formatted error ('Can not load asset ...') is thrown directly.","commonSituations":"Typo'd asset name, asset not included in the built resource packages, loading before resource tables are initialized/updated, or forgetting to pass LoadAssetCallbacks.","solutions":["Verify the asset name/path matches the built asset list (check package catalog).","Pass LoadAssetCallbacks with a failure callback so errors are reported instead of thrown.","Ensure resource initialization (InitResources/UpdateResources or applicable resource mode) completed before loading.","Check ResourceComponent mode (package vs updatable) matches your deployment."],"exampleFix":"// before\nvar obj = resourceComponent.LoadAsset(assetName, typeof(GameObject));\n// after\nresourceComponent.LoadAsset(assetName, typeof(GameObject),\n    new LoadAssetCallbacks(\n        onSuccess, onFailure: (name, status, msg, ud) => Log.Warning($\"Load failed {name}: {status} {msg}\")));","handlingStrategy":"try-catch","validationCode":"// Check asset presence via the framework's HasAsset/asset info API before loading\nbool exists = resourceComponent.HasAsset(assetName);\nif (!exists) { Log.Warning(\"Asset not in catalog: \" + assetName); return; }","typeGuard":null,"tryCatchPattern":"try { resourceComponent.LoadAsset(assetName, typeof(GameObject), new LoadAssetCallbacks(onSuccess,\n    (n, s, m, u) => Log.Error($\"Load failed: {n} [{s}] {m}\"))); }\ncatch (GameFrameworkException ex) { Log.Error(\"LoadAsset threw: \" + ex.Message); }","preventionTips":["Always pass LoadAssetCallbacks with a failure callback","Validate asset names against the build catalog","Finish resource init/update before loading"],"tags":["gameframework","resource-management","asset-loading","missing-asset"],"backgroundTag":"resource-not-found","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}