EllanJiang/GameFramework · error · GameFrameworkException
Asset is invalid.
Error message
Asset is invalid.
What it means
ResourceManager.UnloadAsset(asset) throws this when the asset argument is null. Unloading requires an actual asset object (previously returned by LoadAsset's success callback); there is nothing to release for null, so the framework rejects it immediately.
Solutions
- Null-check the asset before calling UnloadAsset and skip the call when it is null.
- Only invoke UnloadAsset from paths guaranteed to have run after a successful load callback assigned the asset.
- Guard against double-unload by clearing the field after unloading and checking it before unloading.
Example fix
// before
public void Close()
{
m_ResourceManager.UnloadAsset(m_Icon);
}
// after
public void Close()
{
if (m_Icon != null)
{
m_ResourceManager.UnloadAsset(m_Icon);
m_Icon = null;
}
} Defensive patterns
Strategy: validation
Validate before calling
if (asset != null)
{
m_ResourceManager.UnloadAsset(asset);
asset = null;
} Type guard
static bool CanUnload(object asset) => asset != null;
Try / catch
try
{
m_ResourceManager.UnloadAsset(asset);
}
catch (GameFrameworkException ex)
{
Log.Error("UnloadAsset failed: {0}", ex.Message);
} Prevention
- Only assign asset fields from load-success callbacks.
- Set the field to null after unloading to make double-unload checks trivial.
- Null-check assets in cleanup/teardown paths where loads may have failed.
When it happens
Trigger: Calling UnloadAsset with a null reference — e.g. the asset field was never assigned from the load-success callback, or was already set to null after a previous unload.
Common situations: Storing the loaded asset in a field that was reset or cleared elsewhere; double-unload where the second call sees a nulled field; a load that failed so the success callback never populated the asset, then UnloadAsset is called in cleanup.
Related errors
- Resource name is invalid.
- Resource extension is invalid.
- Apply resources complete callback is invalid.
- Update resources complete callback is invalid.
- Scene asset name is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/fa3f52fcca6d11de.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Resource/ResourceManager.cs:1638
}
if (loadAssetCallbacks == null)
{
throw new GameFrameworkException("Load asset callbacks is invalid.");
}
m_ResourceLoader.LoadAsset(assetName, assetType, priority, loadAssetCallbacks, userData);
}
/// <summary>
/// 卸载资源。
/// </summary>
/// <param name="asset">要卸载的资源。</param>
public void UnloadAsset(object asset)
{
if (asset == null)
{
throw new GameFrameworkException("Asset is invalid.");
}
if (m_ResourceLoader == null)
{
return;
}
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))View on GitHub (pinned to d0c010b051)