EllanJiang/GameFramework · error · GameFrameworkException

Can not find asset of scene

Error message

Can not find asset of scene '{0}'.

What it means

UnloadScene looks up the loaded scene's asset in m_SceneToAssetMap; if the scene asset name is not present, the scene was never loaded through this loader (or already unloaded), and the error is thrown instead of calling the helper.

Solutions

  1. Only call UnloadScene with the exact scene asset name previously passed to a successful LoadScene.
  2. Track loaded scenes and skip UnloadScene for names not currently loaded.
  3. Ensure each scene is unloaded exactly once (guard against repeated teardown calls).
  4. Catch GameFrameworkException and log instead of crashing during shutdown sequences.

Example fix

// before
resourceComponent.UnloadScene(sceneName, callbacks); // may throw if not loaded
// after
if (loadedScenes.Contains(sceneName)) {
    loadedScenes.Remove(sceneName);
    resourceComponent.UnloadScene(sceneName, callbacks);
}
Defensive patterns

Strategy: validation

Validate before calling

// Track scenes loaded through LoadScene yourself
if (!loadedScenes.Contains(sceneAssetName)) { Log.Warning("Scene not loaded: " + sceneAssetName); return; }

Try / catch

try { resourceComponent.UnloadScene(sceneAssetName, unloadCallbacks); }
catch (GameFrameworkException ex) { Log.Warning("UnloadScene skipped: " + ex.Message); }

Prevention

When it happens

Trigger: Calling UnloadScene with a scene name that was never loaded via LoadScene, that was already unloaded, or with a name that does not exactly match the loaded scene asset name.

Common situations: Double-unload on scene teardown, unloading a scene loaded through a different resource manager instance, name mismatch (missing 'Assets/...' prefix or wrong case), and unload racing with a failed LoadScene.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at GameFramework/Resource/ResourceManager.ResourceLoader.cs:446

            /// <param name="unloadSceneCallbacks">卸载场景回调函数集。</param>
            /// <param name="userData">用户自定义数据。</param>
            public void UnloadScene(string sceneAssetName, UnloadSceneCallbacks unloadSceneCallbacks, object userData)
            {
                if (m_ResourceManager.m_ResourceHelper == null)
                {
                    throw new GameFrameworkException("You must set resource helper first.");
                }

                object asset = null;
                if (m_SceneToAssetMap.TryGetValue(sceneAssetName, out asset))
                {
                    m_SceneToAssetMap.Remove(sceneAssetName);
                    m_AssetPool.Unspawn(asset);
                    m_AssetPool.ReleaseObject(asset);
                }
                else
                {
                    throw new GameFrameworkException(Utility.Text.Format("Can not find asset of scene '{0}'.", sceneAssetName));
                }

                m_ResourceManager.m_ResourceHelper.UnloadScene(sceneAssetName, unloadSceneCallbacks, userData);
            }

            /// <summary>
            /// 获取二进制资源的实际路径。
            /// </summary>
            /// <param name="binaryAssetName">要获取实际路径的二进制资源的名称。</param>
            /// <returns>二进制资源的实际路径。</returns>
            /// <remarks>此方法仅适用于二进制资源存储在磁盘(而非文件系统)中的情况。若二进制资源存储在文件系统中时,返回值将始终为空。</remarks>
            public string GetBinaryPath(string binaryAssetName)
            {
                ResourceInfo resourceInfo = GetResourceInfo(binaryAssetName);
                if (resourceInfo == null)
                {
                    return null;
                }

View on GitHub (pinned to d0c010b051)