EllanJiang/GameFramework · error · GameFrameworkException

Load asset callbacks is invalid.

Error message

Load asset callbacks is invalid.

What it means

LoadAsset requires a LoadAssetCallbacks instance so the caller can receive success, failure, and dependency-asset callbacks. Passing null would make load results undeliverable, so ResourceManager throws this GameFrameworkException. All LoadAsset overloads ultimately funnel through this check.

Solutions

  1. Always construct and pass LoadAssetCallbacks (at minimum with onLoadAssetFailure set) to LoadAsset.
  2. If you truly need no-op handling, pass a callbacks instance with empty/no-op handlers.
  3. Audit helper methods that forward callbacks and give them a non-null default.

Example fix

// before
m_ResourceManager.LoadAsset(assetName, null); // throws
// after
m_ResourceManager.LoadAsset(assetName, new LoadAssetCallbacks(
    onSuccess: (assetName, asset, duration) => { /* use asset */ },
    onFailure: (assetName, status, errMsg) => Debug.LogError(errMsg)));
Defensive patterns

Strategy: type-guard

Validate before calling

if (loadAssetCallbacks == null) { loadAssetCallbacks = new LoadAssetCallbacks((n,a,d)=>{}, (n,s,m)=>Debug.LogError(m)); }

Type guard

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

Try / catch

try { rm.LoadAsset(name, callbacks); } catch (GameFrameworkException ex) { Debug.LogError(ex.Message); }

Prevention

When it happens

Trigger: Calling LoadAsset(assetName, null) or an overload where the callbacks argument resolves to null — e.g. a cached callbacks object never initialized, or a helper that forwards a null callbacks parameter.

Common situations: Wrapping LoadAsset in a utility whose optional callbacks parameter defaults to null then is forwarded; refactoring removed the 'new LoadAssetCallbacks(...)' construction; passing null intending 'fire and forget' (not supported).

Related errors


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

Appendix: source

Thrown at GameFramework/Resource/ResourceManager.cs:1472

            return m_ResourceLoader.HasAsset(assetName);
        }

        /// <summary>
        /// 异步加载资源。
        /// </summary>
        /// <param name="assetName">要加载资源的名称。</param>
        /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
        public void LoadAsset(string assetName, LoadAssetCallbacks loadAssetCallbacks)
        {
            if (string.IsNullOrEmpty(assetName))
            {
                throw new GameFrameworkException("Asset name is invalid.");
            }

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

            m_ResourceLoader.LoadAsset(assetName, null, Constant.DefaultPriority, loadAssetCallbacks, null);
        }

        /// <summary>
        /// 异步加载资源。
        /// </summary>
        /// <param name="assetName">要加载资源的名称。</param>
        /// <param name="assetType">要加载资源的类型。</param>
        /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
        public void LoadAsset(string assetName, Type assetType, LoadAssetCallbacks loadAssetCallbacks)
        {
            if (string.IsNullOrEmpty(assetName))
            {
                throw new GameFrameworkException("Asset name is invalid.");
            }

View on GitHub (pinned to d0c010b051)