{"record":{"id":"c96613e31300f815","repo":"EllanJiang/GameFramework","slug":"you-must-set-resource-mode-first","errorCode":null,"errorMessage":"You must set resource mode first.","messagePattern":"You must set resource mode first\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.cs","lineNumber":1097,"sourceCode":"            }\n\n            m_ResourceLoader.AddLoadResourceAgentHelper(loadResourceAgentHelper, m_ResourceHelper, m_ReadOnlyPath, m_ReadWritePath, m_DecryptResourceCallback);\n        }\n\n        /// <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>","sourceCodeStart":1079,"sourceCodeEnd":1115,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.cs#L1079-L1115","documentation":"Thrown by GameFramework's ResourceManager when InitResources is called while m_ResourceMode is still ResourceMode.Unspecified. The resource mode (Package vs Updatable vs UpdatableWhilePlaying) must be configured before any resource pipeline API can run, because the mode decides which internal helper components are used.","triggerScenarios":"Calling ResourceManager.InitResources(initResourcesCompleteCallback) without first calling SetResourceMode(ResourceMode.Package) (or another concrete mode).","commonSituations":"Forgetting SetResourceMode during Unity GameFramework bootstrap, initializing the resource component before configuration, or a script execution order issue where InitResources runs before setup code.","solutions":["Call resourceComponent.SetResourceMode(ResourceMode.Package) before InitResources (Package mode for shipped assets).","Use ResourceMode.Updatable or UpdatableWhilePlaying if you intend the updatable pipeline, then use CheckVersionList/UpdateVersionList instead of InitResources.","Verify bootstrap order: SetResourceMode -> InitResources (Package) or CheckVersionList/UpdateVersionList (Updatable)."],"exampleFix":"// before\nm_ResourceComponent.InitResources(OnInitResourcesComplete);\n// after\nm_ResourceComponent.SetResourceMode(ResourceMode.Package);\nm_ResourceComponent.InitResources(OnInitResourcesComplete);","handlingStrategy":"validation","validationCode":"if (m_ResourceComponent.ResourceMode == ResourceMode.Unspecified)\n    m_ResourceComponent.SetResourceMode(ResourceMode.Package);\nm_ResourceComponent.InitResources(OnInitResourcesComplete);","typeGuard":null,"tryCatchPattern":"try { m_ResourceComponent.InitResources(cb); }\ncatch (GameFrameworkException e) { Log.Fatal(\"InitResources before SetResourceMode: {0}\", e.Message); }","preventionTips":["Always call SetResourceMode as the first resource API in bootstrap.","Keep mode configuration in the ResourceComponent Awake so it cannot race.","Branch bootstrap code on ResourceMode."],"tags":["unity","gameframework","resource-manager","initialization-order","resource-mode"],"backgroundTag":"invalid-state-transition","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"}