EllanJiang/GameFramework · error · GameFrameworkException

Load scene callbacks is invalid.

Error message

Load scene callbacks is invalid.

What it means

ResourceManager.LoadScene(sceneAssetName, loadSceneCallbacks) throws this when loadSceneCallbacks is null. Scene loading is asynchronous, so the framework requires a LoadSceneCallbacks object to always deliver success, failure, and dependency-asset notifications.

Solutions

  1. Pass a constructed LoadSceneCallbacks instance with at least the scene-load success and failure handlers.
  2. Ensure any helper/wrapper always supplies a default callbacks object when the caller omits one.
  3. Use empty-bodied handlers instead of null when notifications are not needed.

Example fix

// before
m_ResourceManager.LoadScene(sceneAssetName, null);
// after
var callbacks = new LoadSceneCallbacks(OnSceneLoadSuccess, OnSceneLoadFailure, OnSceneLoadUpdate, OnSceneLoadDependencyAsset);
m_ResourceManager.LoadScene(sceneAssetName, callbacks);
Defensive patterns

Strategy: validation

Validate before calling

if (loadSceneCallbacks == null)
{
    loadSceneCallbacks = new LoadSceneCallbacks(OnSceneLoadSuccess, OnSceneLoadFailure);
}

Type guard

static bool HasCallbacks(LoadSceneCallbacks c) => c != null;

Try / catch

try
{
    m_ResourceManager.LoadScene(sceneAssetName, callbacks);
}
catch (GameFrameworkException ex)
{
    Log.Error("LoadScene failed: {0}", ex.Message);
}

Prevention

When it happens

Trigger: Calling LoadScene with null as the LoadSceneCallbacks parameter, or a helper that conditionally builds callbacks returning null.

Common situations: A wrapper with an optional callbacks argument defaulting to null; a refactoring that removed the LoadSceneCallbacks construction; passing null because scene load 'always succeeds' in the current flow.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at GameFramework/Resource/ResourceManager.cs:1663

            m_ResourceLoader.UnloadAsset(asset);
        }

        /// <summary>
        /// 异步加载场景。
        /// </summary>
        /// <param name="sceneAssetName">要加载场景资源的名称。</param>
        /// <param name="loadSceneCallbacks">加载场景回调函数集。</param>
        public void LoadScene(string sceneAssetName, LoadSceneCallbacks loadSceneCallbacks)
        {
            if (string.IsNullOrEmpty(sceneAssetName))
            {
                throw new GameFrameworkException("Scene asset name is invalid.");
            }

            if (loadSceneCallbacks == null)
            {
                throw new GameFrameworkException("Load scene callbacks is invalid.");
            }

            m_ResourceLoader.LoadScene(sceneAssetName, Constant.DefaultPriority, loadSceneCallbacks, null);
        }

        /// <summary>
        /// 异步加载场景。
        /// </summary>
        /// <param name="sceneAssetName">要加载场景资源的名称。</param>
        /// <param name="priority">加载场景资源的优先级。</param>
        /// <param name="loadSceneCallbacks">加载场景回调函数集。</param>
        public void LoadScene(string sceneAssetName, int priority, LoadSceneCallbacks loadSceneCallbacks)
        {
            if (string.IsNullOrEmpty(sceneAssetName))
            {
                throw new GameFrameworkException("Scene asset name is invalid.");
            }

View on GitHub (pinned to d0c010b051)