EllanJiang/GameFramework · error · GameFrameworkException

Resource mode is invalid.

Error message

Resource mode is invalid.

What it means

SetResourceMode throws GameFrameworkException when resourceMode equals ResourceMode.Unspecified. Unspecified is a sentinel meaning 'not configured'; the framework requires a concrete mode (e.g. Package, PackageAndUpdatable) to operate.

Solutions

  1. Pass a concrete ResourceMode value such as ResourceMode.Package or ResourceMode.PackageAndUpdatable
  2. Fix the configuration source that yields Unspecified
  3. Check for invalid int-to-enum casts producing the Unspecified (0) value

Example fix

// before
resourceComponent.SetResourceMode((ResourceMode)config.Mode); // config.Mode == 0 -> Unspecified
// after
var mode = (ResourceMode)config.Mode;
if (mode != ResourceMode.Unspecified) resourceComponent.SetResourceMode(mode);
Defensive patterns

Strategy: validation

Validate before calling

if (mode == ResourceMode.Unspecified)
    throw new InvalidOperationException("Resource mode must be a concrete value, not Unspecified");
resourceComponent.SetResourceMode(mode);

Type guard

bool IsValidResourceMode(ResourceMode m) => m != ResourceMode.Unspecified && System.Enum.IsDefined(typeof(ResourceMode), m);

Try / catch

try { resourceComponent.SetResourceMode(mode); }
catch (GameFrameworkException ex) { Log.Error("Invalid resource mode: {0}", ex.Message); }

Prevention

When it happens

Trigger: Calling SetResourceMode(ResourceMode.Unspecified), typically because the mode value was never loaded from configuration or defaulted incorrectly.

Common situations: Config file missing a resource mode entry, an enum cast from an unrecognized int, or forgetting to set the mode in the Unity inspector before startup.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at GameFramework/Resource/ResourceManager.cs:909

            }

            if (m_ResourceLoader.TotalAgentCount > 0)
            {
                throw new GameFrameworkException("You must set read-write path before add load resource agent helper.");
            }

            m_ReadWritePath = readWritePath;
        }

        /// <summary>
        /// 设置资源模式。
        /// </summary>
        /// <param name="resourceMode">资源模式。</param>
        public void SetResourceMode(ResourceMode resourceMode)
        {
            if (resourceMode == ResourceMode.Unspecified)
            {
                throw new GameFrameworkException("Resource mode is invalid.");
            }

            if (m_RefuseSetFlag)
            {
                throw new GameFrameworkException("You can not set resource mode at this time.");
            }

            if (m_ResourceMode == ResourceMode.Unspecified)
            {
                m_ResourceMode = resourceMode;

                if (m_ResourceMode == ResourceMode.Package)
                {
                    m_PackageVersionListSerializer = new PackageVersionListSerializer();

                    m_ResourceIniter = new ResourceIniter(this);
                    m_ResourceIniter.ResourceInitComplete += OnIniterResourceInitComplete;
                }

View on GitHub (pinned to d0c010b051)