{"record":{"id":"c020b93e0bcfb4b2","repo":"EllanJiang/GameFramework","slug":"you-can-not-use-initresources-without-package-resource-mode","errorCode":null,"errorMessage":"You can not use InitResources without package resource mode.","messagePattern":"You can not use InitResources without package resource mode\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.cs","lineNumber":1102,"sourceCode":"        /// <summary>\n        /// 使用单机模式并初始化资源。\n        /// </summary>\n        /// <param name=\"initResourcesCompleteCallback\">使用单机模式并初始化资源完成时的回调函数。</param>\n        public void InitResources(InitResourcesCompleteCallback initResourcesCompleteCallback)\n        {\n            if (initResourcesCompleteCallback == null)\n            {\n                throw new GameFrameworkException(\"Init resources complete callback is invalid.\");\n            }\n\n            if (m_ResourceMode == ResourceMode.Unspecified)\n            {\n                throw new GameFrameworkException(\"You must set resource mode first.\");\n            }\n\n            if (m_ResourceMode != ResourceMode.Package)\n            {\n                throw new GameFrameworkException(\"You can not use InitResources without package resource mode.\");\n            }\n\n            if (m_ResourceIniter == null)\n            {\n                throw new GameFrameworkException(\"You can not use InitResources at this time.\");\n            }\n\n            m_RefuseSetFlag = true;\n            m_InitResourcesCompleteCallback = initResourcesCompleteCallback;\n            m_ResourceIniter.InitResources(m_CurrentVariant);\n        }\n\n        /// <summary>\n        /// 使用可更新模式并检查版本资源列表。\n        /// </summary>\n        /// <param name=\"latestInternalResourceVersion\">最新的内部资源版本号。</param>\n        /// <returns>检查版本资源列表结果。</returns>\n        public CheckVersionListResult CheckVersionList(int latestInternalResourceVersion)","sourceCodeStart":1084,"sourceCodeEnd":1120,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.cs#L1084-L1120","documentation":"Thrown by ResourceManager.InitResources when the resource mode is set but is not ResourceMode.Package. InitResources is the Package-mode initialization path; Updatable/UpdatableWhilePlaying modes use the version-list flow (CheckVersionList/UpdateVersionList) instead.","triggerScenarios":"Calling InitResources while m_ResourceMode is ResourceMode.Updatable or ResourceMode.UpdatableWhilePlaying.","commonSituations":"A project switched to hot-update (updatable) resource mode but kept the Package-style InitResources bootstrap call, often after a resource pipeline migration or copying sample code between projects.","solutions":["If using updatable resources, remove InitResources and call CheckVersionList + UpdateVersionList + UpdateResources instead.","If you really want Package mode, call SetResourceMode(ResourceMode.Package) before InitResources.","Audit the bootstrap procedure so the mode and the init API pair correctly."],"exampleFix":"// before\nresourceComponent.SetResourceMode(ResourceMode.UpdatableWhilePlaying);\nresourceComponent.InitResources(OnInitResourcesComplete);\n// after\nresourceComponent.SetResourceMode(ResourceMode.UpdatableWhilePlaying);\nresourceComponent.CheckVersionList(latestInternalResourceVersion);","handlingStrategy":"validation","validationCode":"if (m_ResourceComponent.ResourceMode != ResourceMode.Package)\n    throw new InvalidOperationException(\"InitResources requires Package mode\");\nm_ResourceComponent.InitResources(OnInitResourcesComplete);","typeGuard":null,"tryCatchPattern":"try { m_ResourceComponent.InitResources(cb); }\ncatch (GameFrameworkException e) { Log.Fatal(\"InitResources called in non-Package mode: {0}\", e.Message); }","preventionTips":["Pair each mode with its correct init API: Package->InitResources, Updatable->CheckVersionList/UpdateVersionList.","Gate hot-update code with a mode check.","Avoid copying bootstrap code between Package and Updatable projects."],"tags":["unity","gameframework","resource-manager","resource-mode","wrong-api"],"backgroundTag":"unsupported-operation","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}