EllanJiang/GameFramework · error · GameFrameworkException

You must set resource mode first.

Error message

You must set resource mode first.

What it means

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.

Solutions

  1. Call resourceComponent.SetResourceMode(ResourceMode.Package) before InitResources (Package mode for shipped assets).
  2. Use ResourceMode.Updatable or UpdatableWhilePlaying if you intend the updatable pipeline, then use CheckVersionList/UpdateVersionList instead of InitResources.
  3. Verify bootstrap order: SetResourceMode -> InitResources (Package) or CheckVersionList/UpdateVersionList (Updatable).

Example fix

// before
m_ResourceComponent.InitResources(OnInitResourcesComplete);
// after
m_ResourceComponent.SetResourceMode(ResourceMode.Package);
m_ResourceComponent.InitResources(OnInitResourcesComplete);
Defensive patterns

Strategy: validation

Validate before calling

if (m_ResourceComponent.ResourceMode == ResourceMode.Unspecified)
    m_ResourceComponent.SetResourceMode(ResourceMode.Package);
m_ResourceComponent.InitResources(OnInitResourcesComplete);

Try / catch

try { m_ResourceComponent.InitResources(cb); }
catch (GameFrameworkException e) { Log.Fatal("InitResources before SetResourceMode: {0}", e.Message); }

Prevention

When it happens

Trigger: Calling ResourceManager.InitResources(initResourcesCompleteCallback) without first calling SetResourceMode(ResourceMode.Package) (or another concrete mode).

Common situations: Forgetting SetResourceMode during Unity GameFramework bootstrap, initializing the resource component before configuration, or a script execution order issue where InitResources runs before setup code.

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


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/c96613e31300f815. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Resource/ResourceManager.cs:1097

            }

            m_ResourceLoader.AddLoadResourceAgentHelper(loadResourceAgentHelper, m_ResourceHelper, m_ReadOnlyPath, m_ReadWritePath, m_DecryptResourceCallback);
        }

        /// <summary>
        /// 使用单机模式并初始化资源。
        /// </summary>
        /// <param name="initResourcesCompleteCallback">使用单机模式并初始化资源完成时的回调函数。</param>
        public void InitResources(InitResourcesCompleteCallback initResourcesCompleteCallback)
        {
            if (initResourcesCompleteCallback == null)
            {
                throw new GameFrameworkException("Init resources complete callback is invalid.");
            }

            if (m_ResourceMode == ResourceMode.Unspecified)
            {
                throw new GameFrameworkException("You must set resource mode first.");
            }

            if (m_ResourceMode != ResourceMode.Package)
            {
                throw new GameFrameworkException("You can not use InitResources without package resource mode.");
            }

            if (m_ResourceIniter == null)
            {
                throw new GameFrameworkException("You can not use InitResources at this time.");
            }

            m_RefuseSetFlag = true;
            m_InitResourcesCompleteCallback = initResourcesCompleteCallback;
            m_ResourceIniter.InitResources(m_CurrentVariant);
        }

        /// <summary>

View on GitHub (pinned to d0c010b051)