EllanJiang/GameFramework · error · GameFrameworkException

You can not use InitResources without package resource mode.

Error message

You can not use InitResources without package resource mode.

What it means

Thrown by ResourceManager.InitResources when the resource mode is set but is not ResourceMode.Package. InitResources is the Package-mode initialization path; Updatable/UpdatableWhilePlaying modes use the version-list flow (CheckVersionList/UpdateVersionList) instead.

Solutions

  1. If using updatable resources, remove InitResources and call CheckVersionList + UpdateVersionList + UpdateResources instead.
  2. If you really want Package mode, call SetResourceMode(ResourceMode.Package) before InitResources.
  3. Audit the bootstrap procedure so the mode and the init API pair correctly.

Example fix

// before
resourceComponent.SetResourceMode(ResourceMode.UpdatableWhilePlaying);
resourceComponent.InitResources(OnInitResourcesComplete);
// after
resourceComponent.SetResourceMode(ResourceMode.UpdatableWhilePlaying);
resourceComponent.CheckVersionList(latestInternalResourceVersion);
Defensive patterns

Strategy: validation

Validate before calling

if (m_ResourceComponent.ResourceMode != ResourceMode.Package)
    throw new InvalidOperationException("InitResources requires Package mode");
m_ResourceComponent.InitResources(OnInitResourcesComplete);

Try / catch

try { m_ResourceComponent.InitResources(cb); }
catch (GameFrameworkException e) { Log.Fatal("InitResources called in non-Package mode: {0}", e.Message); }

Prevention

When it happens

Trigger: Calling InitResources while m_ResourceMode is ResourceMode.Updatable or ResourceMode.UpdatableWhilePlaying.

Common situations: A project switched to hot-update (updatable) resource mode but kept the Package-style InitResources bootstrap call, often after a resource pipeline migration or copying sample code between projects.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at GameFramework/Resource/ResourceManager.cs:1102

        /// <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>
        /// 使用可更新模式并检查版本资源列表。
        /// </summary>
        /// <param name="latestInternalResourceVersion">最新的内部资源版本号。</param>
        /// <returns>检查版本资源列表结果。</returns>
        public CheckVersionListResult CheckVersionList(int latestInternalResourceVersion)

View on GitHub (pinned to d0c010b051)