{"record":{"id":"99247e6828b17107","repo":"EllanJiang/GameFramework","slug":"you-must-set-read-only-path-before-add-load-resource-agent","errorCode":null,"errorMessage":"You must set read-only path before add load resource agent helper.","messagePattern":"You must set read-only path before add load resource agent helper\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.cs","lineNumber":871,"sourceCode":"        /// <summary>\n        /// 设置资源只读区路径。\n        /// </summary>\n        /// <param name=\"readOnlyPath\">资源只读区路径。</param>\n        public void SetReadOnlyPath(string readOnlyPath)\n        {\n            if (string.IsNullOrEmpty(readOnlyPath))\n            {\n                throw new GameFrameworkException(\"Read-only path is invalid.\");\n            }\n\n            if (m_RefuseSetFlag)\n            {\n                throw new GameFrameworkException(\"You can not set read-only path at this time.\");\n            }\n\n            if (m_ResourceLoader.TotalAgentCount > 0)\n            {\n                throw new GameFrameworkException(\"You must set read-only path before add load resource agent helper.\");\n            }\n\n            m_ReadOnlyPath = readOnlyPath;\n        }\n\n        /// <summary>\n        /// 设置资源读写区路径。\n        /// </summary>\n        /// <param name=\"readWritePath\">资源读写区路径。</param>\n        public void SetReadWritePath(string readWritePath)\n        {\n            if (string.IsNullOrEmpty(readWritePath))\n            {\n                throw new GameFrameworkException(\"Read-write path is invalid.\");\n            }\n\n            if (m_RefuseSetFlag)\n            {","sourceCodeStart":853,"sourceCodeEnd":889,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.cs#L853-L889","documentation":"SetReadOnlyPath throws this when the resource loader already has load resource agent helpers added (m_ResourceLoader.TotalAgentCount > 0). Paths must be configured before any agents exist because agents capture the path environment at creation time.","triggerScenarios":"Calling SetReadOnlyPath after AddLoadResourceAgentHelper (or equivalent agent registration) has created one or more agents.","commonSituations":"Calling the setter after triggering resource system startup/agent creation, or reconfiguring paths at runtime to redirect resource loading.","solutions":["Call SetReadOnlyPath before adding any load resource agent helpers","Reorder startup: paths first, then agent helpers","If reconfiguration is truly needed, recreate/reinitialize the resource module"],"exampleFix":"// before\nloader.AddLoadResourceAgentHelper(helper);\nresourceComponent.SetReadOnlyPath(path); // agents exist already\n// after\nresourceComponent.SetReadOnlyPath(path);\nloader.AddLoadResourceAgentHelper(helper);","handlingStrategy":"validation","validationCode":"if (resourceComponent.ResourceLoaderTotalAgentCount == 0) resourceComponent.SetReadOnlyPath(path);","typeGuard":null,"tryCatchPattern":"try { resourceComponent.SetReadOnlyPath(path); }\ncatch (GameFrameworkException) { Log.Error(\"Set read-only path before adding load resource agent helpers.\"); }","preventionTips":["Establish a fixed init order: paths -> resource mode -> agent helpers","Never interleave agent creation with path configuration","Document the ordering contract for the resource module"],"tags":["gameframework","unity","resource","initialization-order"],"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-15T23:17:13.987Z"}