EllanJiang/GameFramework · error · GameFrameworkException
You must set decrypt resource callback before add load…
Error message
You must set decrypt resource callback before add load resource agent helper.
What it means
Thrown by ResourceManager.SetDecryptResourceCallback if load-resource agent helpers have already been added (m_ResourceLoader.TotalAgentCount > 0). The decrypt callback is applied to agent helpers at creation time, so setting it afterwards is too late; the library forbids the late assignment.
Solutions
- Call SetDecryptResourceCallback before any AddLoadResourceAgentHelper call, e.g. in Awake with a lower Script Execution Order
- Use [DefaultExecutionOrder] or Project Settings > Script Execution Order to force the callback setup script to run first
- If no custom decryption is needed, skip SetDecryptResourceCallback entirely (a default callback is used)
Example fix
// before resourceManager.AddLoadResourceAgentHelper(helper); resourceManager.SetDecryptResourceCallback(MyDecrypt); // throws // after resourceManager.SetDecryptResourceCallback(MyDecrypt); resourceManager.AddLoadResourceAgentHelper(helper);
Defensive patterns
Strategy: validation
Validate before calling
if (resourceManager.TotalAgentCount == 0) resourceManager.SetDecryptResourceCallback(myDecrypt); else throw new InvalidOperationException("Set decrypt callback before adding agent helpers"); Type guard
bool CanSetDecryptCallback(ResourceManager rm) => rm.TotalAgentCount == 0;
Try / catch
try { resourceManager.SetDecryptResourceCallback(myDecrypt); } catch (GameFrameworkException ex) { Debug.LogError($"Call SetDecryptResourceCallback before AddLoadResourceAgentHelper: {ex.Message}"); } Prevention
- Set all callbacks before adding any agent helpers
- Control Unity script execution order ([DefaultExecutionOrder])
- Note the default decrypt callback exists if no custom logic is needed
When it happens
Trigger: Calling AddLoadResourceAgentHelper (directly or via ResourceComponent helpers) before calling SetDecryptResourceCallback with a custom callback.
Common situations: Unity execution-order issues where ResourceComponent.Start adds agent helpers before a script sets the callback; forgetting that helper registration happens in Awake/Start.
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 resource helper before add load resource agent…
- 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/37a409d7592d2f4a.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Resource/ResourceManager.cs:1035
m_VersionListProcessor.SetDownloadManager(downloadManager);
}
if (m_ResourceUpdater != null)
{
m_ResourceUpdater.SetDownloadManager(downloadManager);
}
}
/// <summary>
/// 设置解密资源回调函数。
/// </summary>
/// <param name="decryptResourceCallback">要设置的解密资源回调函数。</param>
/// <remarks>如果不设置,将使用默认的解密资源回调函数。</remarks>
public void SetDecryptResourceCallback(DecryptResourceCallback decryptResourceCallback)
{
if (m_ResourceLoader.TotalAgentCount > 0)
{
throw new GameFrameworkException("You must set decrypt resource callback before add load resource agent helper.");
}
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)
{View on GitHub (pinned to d0c010b051)