EllanJiang/GameFramework · error · GameFrameworkException

Asset target ' ' reference count is ' ' larger than 0.

Error message

Asset target '{0}' reference count is '{1}' larger than 0.

What it means

AssetObject.Release checks, during explicit release or non-shutdown release, that the asset's Target still has zero entries in ResourceLoader's m_AssetDependencyCount dictionary. If other assets still depend on this target, releasing it would break them, so the framework throws with the target name and current reference count. It signals a reference-counting invariant violation in the caller's asset usage.

Solutions

  1. Release dependent/child assets first, then the asset that owns the target.
  2. Let ResourceLoader manage lifecycles — unload only assets you loaded, in reverse dependency order.
  3. Audit the m_AssetDependencyCount bookkeeping if you extended the loader, ensuring Increment/Decrement pairs match.
  4. If this fires during shutdown, ensure shutdown path uses isShutdown=true release semantics rather than manual UnloadAsset calls.

Example fix

// before
loader.UnloadAsset(sharedMaterial);
loader.UnloadAsset(prefab); // prefab still depends on sharedMaterial
// after
loader.UnloadAsset(prefab);   // release dependent first
loader.UnloadAsset(sharedMaterial);
Defensive patterns

Strategy: try-catch

Validate before calling

if (m_ResourceLoader.m_AssetDependencyCount.TryGetValue(target, out var rc) && rc > 0)
    Log.Warning("Cannot release {0}: {1} dependents remain.", name, rc);

Try / catch

try { loader.UnloadAsset(asset); }
catch (GameFrameworkException ex) { Log.Error("Release blocked: {0}", ex.Message); /* release dependents first, then retry */ }

Prevention

When it happens

Trigger: Calling UnloadAsset/Release for an asset whose target is still referenced as a dependency by other live assets (targetReferenceCount > 0), or releasing assets in the wrong order during shutdown-adjacent flows.

Common situations: Releasing a parent/scene asset before its dependent assets; double-managing lifecycles where custom code unloads assets the loader still tracks; cached asset handles held by UI that unload a shared dependency.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at GameFramework/Resource/ResourceManager.ResourceLoader.AssetObject.cs:115

                }

                protected internal override void OnUnspawn()
                {
                    base.OnUnspawn();
                    foreach (object dependencyAsset in m_DependencyAssets)
                    {
                        m_ResourceLoader.m_AssetPool.Unspawn(dependencyAsset);
                    }
                }

                protected internal override void Release(bool isShutdown)
                {
                    if (!isShutdown)
                    {
                        int targetReferenceCount = 0;
                        if (m_ResourceLoader.m_AssetDependencyCount.TryGetValue(Target, out targetReferenceCount) && targetReferenceCount > 0)
                        {
                            throw new GameFrameworkException(Utility.Text.Format("Asset target '{0}' reference count is '{1}' larger than 0.", Name, targetReferenceCount));
                        }

                        foreach (object dependencyAsset in m_DependencyAssets)
                        {
                            int referenceCount = 0;
                            if (m_ResourceLoader.m_AssetDependencyCount.TryGetValue(dependencyAsset, out referenceCount))
                            {
                                m_ResourceLoader.m_AssetDependencyCount[dependencyAsset] = referenceCount - 1;
                            }
                            else
                            {
                                throw new GameFrameworkException(Utility.Text.Format("Asset target '{0}' dependency asset reference count is invalid.", Name));
                            }
                        }

                        m_ResourceLoader.m_ResourcePool.Unspawn(m_Resource);
                    }

View on GitHub (pinned to d0c010b051)