{"record":{"id":"9150c73ac7c6c353","repo":"EllanJiang/GameFramework","slug":"you-must-set-resource-helper-before-add-load-resource-agent","errorCode":null,"errorMessage":"You must set resource helper before add load resource agent helper.","messagePattern":"You must set resource helper before add load resource agent helper\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.cs","lineNumber":1054,"sourceCode":"            }\n\n            m_DecryptResourceCallback = decryptResourceCallback;\n        }\n\n        /// <summary>\n        /// 设置资源辅助器。\n        /// </summary>\n        /// <param name=\"resourceHelper\">资源辅助器。</param>\n        public void SetResourceHelper(IResourceHelper resourceHelper)\n        {\n            if (resourceHelper == null)\n            {\n                throw new GameFrameworkException(\"Resource helper is invalid.\");\n            }\n\n            if (m_ResourceLoader.TotalAgentCount > 0)\n            {\n                throw new GameFrameworkException(\"You must set resource helper before add load resource agent helper.\");\n            }\n\n            m_ResourceHelper = resourceHelper;\n        }\n\n        /// <summary>\n        /// 增加加载资源代理辅助器。\n        /// </summary>\n        /// <param name=\"loadResourceAgentHelper\">要增加的加载资源代理辅助器。</param>\n        public void AddLoadResourceAgentHelper(ILoadResourceAgentHelper loadResourceAgentHelper)\n        {\n            if (m_ResourceHelper == null)\n            {\n                throw new GameFrameworkException(\"Resource helper is invalid.\");\n            }\n\n            if (string.IsNullOrEmpty(m_ReadOnlyPath))\n            {","sourceCodeStart":1036,"sourceCodeEnd":1072,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.cs#L1036-L1072","documentation":"Thrown by ResourceManager.SetResourceHelper when a load-resource agent helper has already been added (m_ResourceLoader.TotalAgentCount > 0). The resource helper is passed to each agent helper at registration time, so it must be set before helpers are added; late assignment is rejected.","triggerScenarios":"Calling AddLoadResourceAgentHelper first and SetResourceHelper afterwards, e.g. helper registration happens in ResourceComponent.Start while SetResourceHelper is called later.","commonSituations":"Script execution order issues in Unity; moving SetResourceHelper after initial resource load setup; forgetting the mandatory ordering between the two methods.","solutions":["Call SetResourceHelper before any AddLoadResourceAgentHelper call","Set the ResourceHelper serialized field on ResourceComponent so it applies before Start registers helpers","Adjust Script Execution Order so the configuration script runs first"],"exampleFix":"// before\nresourceManager.AddLoadResourceAgentHelper(helper);\nresourceManager.SetResourceHelper(resHelper); // throws\n// after\nresourceManager.SetResourceHelper(resHelper);\nresourceManager.AddLoadResourceAgentHelper(helper);","handlingStrategy":"validation","validationCode":"if (resourceManager.TotalAgentCount > 0) throw new InvalidOperationException(\"SetResourceHelper must be called before adding agent helpers\");","typeGuard":"bool CanSetResourceHelper(ResourceManager rm) => rm.TotalAgentCount == 0;","tryCatchPattern":"try { resourceManager.SetResourceHelper(resourceHelper); } catch (GameFrameworkException ex) { Debug.LogError($\"Set resource helper before adding agent helpers: {ex.Message}\"); }","preventionTips":["Order calls: SetResourceHelper before AddLoadResourceAgentHelper","Set the ResourceHelper field on ResourceComponent so ordering is automatic","Use script execution order to guarantee configuration runs first"],"tags":["resource","gameframework","call-order","initialization"],"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"}