EllanJiang/GameFramework · error · GameFrameworkException

Scene asset name is invalid.

Error message

Scene asset name is invalid.

What it means

SceneManager.SceneIsLoaded throws GameFrameworkException when the sceneAssetName argument is null or empty. The library treats a missing scene asset name as a programmer error rather than returning false, so the call fails fast at the boundary. A valid non-empty asset name (e.g. 'Assets/Scenes/Main.unity') is required for the membership check against loaded scenes.

Solutions

  1. Ensure sceneAssetName is a non-null, non-empty string before calling SceneIsLoaded
  2. Fix the source of the empty value (blank config field, failed lookup, uninitialized variable)
  3. Use the null/empty guard pattern before any SceneManager scene query

Example fix

// before
bool loaded = sceneManager.SceneIsLoaded(sceneName);
// after
if (!string.IsNullOrEmpty(sceneName))
{
    bool loaded = sceneManager.SceneIsLoaded(sceneName);
}
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(sceneAssetName)) throw new ArgumentException("sceneAssetName is required", nameof(sceneAssetName));

Type guard

bool IsValidSceneName(string name) => !string.IsNullOrEmpty(name);

Try / catch

try { ok = sceneManager.SceneIsLoaded(name); } catch (GameFrameworkException ex) { Log.Error(ex.Message); }

Prevention

When it happens

Trigger: Calling SceneIsLoaded(null) or SceneIsLoaded("") directly, or indirectly via LoadScene/UnloadScene paths that forward an unvalidated sceneAssetName into this check.

Common situations: Reading the scene name from a config/inspector field left blank, constructing asset names with string concatenation that yields an empty string, or passing a variable that was never initialized before checking scene state.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at GameFramework/Scene/SceneManager.cs:206

        {
            if (resourceManager == null)
            {
                throw new GameFrameworkException("Resource manager is invalid.");
            }

            m_ResourceManager = resourceManager;
        }

        /// <summary>
        /// 获取场景是否已加载。
        /// </summary>
        /// <param name="sceneAssetName">场景资源名称。</param>
        /// <returns>场景是否已加载。</returns>
        public bool SceneIsLoaded(string sceneAssetName)
        {
            if (string.IsNullOrEmpty(sceneAssetName))
            {
                throw new GameFrameworkException("Scene asset name is invalid.");
            }

            return m_LoadedSceneAssetNames.Contains(sceneAssetName);
        }

        /// <summary>
        /// 获取已加载场景的资源名称。
        /// </summary>
        /// <returns>已加载场景的资源名称。</returns>
        public string[] GetLoadedSceneAssetNames()
        {
            return m_LoadedSceneAssetNames.ToArray();
        }

        /// <summary>
        /// 获取已加载场景的资源名称。
        /// </summary>
        /// <param name="results">已加载场景的资源名称。</param>

View on GitHub (pinned to d0c010b051)