EllanJiang/GameFramework · error · GameFrameworkException
You must set resource helper before add load resource agent…
Error message
You must set resource helper before add load resource agent helper.
What it means
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.
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
Example fix
// before resourceManager.AddLoadResourceAgentHelper(helper); resourceManager.SetResourceHelper(resHelper); // throws // after resourceManager.SetResourceHelper(resHelper); resourceManager.AddLoadResourceAgentHelper(helper);
Defensive patterns
Strategy: validation
Validate before calling
if (resourceManager.TotalAgentCount > 0) throw new InvalidOperationException("SetResourceHelper must be called before adding agent helpers"); Type guard
bool CanSetResourceHelper(ResourceManager rm) => rm.TotalAgentCount == 0;
Try / catch
try { resourceManager.SetResourceHelper(resourceHelper); } catch (GameFrameworkException ex) { Debug.LogError($"Set resource helper before adding agent helpers: {ex.Message}"); } Prevention
- Order calls: SetResourceHelper before AddLoadResourceAgentHelper
- Set the ResourceHelper field on ResourceComponent so ordering is automatic
- Use script execution order to guarantee configuration runs first
When it happens
Trigger: Calling AddLoadResourceAgentHelper first and SetResourceHelper afterwards, e.g. helper registration happens in ResourceComponent.Start while SetResourceHelper is called later.
Common situations: Script execution order issues in Unity; moving SetResourceHelper after initial resource load setup; forgetting the mandatory ordering between the two methods.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- You must set decrypt resource callback before add load…
- Read-only path is invalid.
- Object pool manager is invalid.
- File system manager is invalid.
- Resource manager is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/9150c73ac7c6c353.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Resource/ResourceManager.cs:1054
}
m_DecryptResourceCallback = decryptResourceCallback;
}
/// <summary>
/// 设置资源辅助器。
/// </summary>
/// <param name="resourceHelper">资源辅助器。</param>
public void SetResourceHelper(IResourceHelper resourceHelper)
{
if (resourceHelper == null)
{
throw new GameFrameworkException("Resource helper is invalid.");
}
if (m_ResourceLoader.TotalAgentCount > 0)
{
throw new GameFrameworkException("You must set resource helper before add load resource agent helper.");
}
m_ResourceHelper = resourceHelper;
}
/// <summary>
/// 增加加载资源代理辅助器。
/// </summary>
/// <param name="loadResourceAgentHelper">要增加的加载资源代理辅助器。</param>
public void AddLoadResourceAgentHelper(ILoadResourceAgentHelper loadResourceAgentHelper)
{
if (m_ResourceHelper == null)
{
throw new GameFrameworkException("Resource helper is invalid.");
}
if (string.IsNullOrEmpty(m_ReadOnlyPath))
{View on GitHub (pinned to d0c010b051)