EllanJiang/GameFramework · error · GameFrameworkException

Target is invalid.

Error message

Target is invalid.

What it means

ObjectPool<T>.Unspawn(object target) throws GameFrameworkException('Target is invalid.') when the raw target reference is null. The overload used for the actual recycle logic requires a non-null target that can be resolved back to a pooled Object<T> via GetObject.

Solutions

  1. Guard the target for null before calling the Unspawn(object) overload.
  2. Ensure the preceding Unspawn(T) call received a non-null object so Target is valid.
  3. Log the call site when target is null to find the upstream null source.

Example fix

// before
pool.Unspawn(entity.Target);
// after
if (entity?.Target != null) pool.Unspawn(entity.Target);
Defensive patterns

Strategy: validation

Validate before calling

if (target == null) { Log.Warning("Unspawn skipped: null target"); return; }
pool.Unspawn(target);

Type guard

bool HasTarget(object target) => target != null;

Try / catch

try { pool.Unspawn(target); } catch (GameFrameworkException ex) when (ex.Message == "Target is invalid.") { Log.Warning("Unspawn target was null"); }

Prevention

When it happens

Trigger: Calling Unspawn(obj.Target) where obj was null (this guards the internal delegation), or calling the object-target overload with a null reference directly.

Common situations: Chained recycle helpers that pass through a null; generic recycle utilities that don't check the target before delegating.

Related errors


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

Appendix: source

Thrown at GameFramework/ObjectPool/ObjectPoolManager.ObjectPool.cs:302

            public void Unspawn(T obj)
            {
                if (obj == null)
                {
                    throw new GameFrameworkException("Object is invalid.");
                }

                Unspawn(obj.Target);
            }

            /// <summary>
            /// 回收对象。
            /// </summary>
            /// <param name="target">要回收的对象。</param>
            public void Unspawn(object target)
            {
                if (target == null)
                {
                    throw new GameFrameworkException("Target is invalid.");
                }

                Object<T> internalObject = GetObject(target);
                if (internalObject != null)
                {
                    internalObject.Unspawn();
                    if (Count > m_Capacity && internalObject.SpawnCount <= 0)
                    {
                        Release();
                    }
                }
                else
                {
                    throw new GameFrameworkException(Utility.Text.Format("Can not find target in object pool '{0}', target type is '{1}', target value is '{2}'.", new TypeNamePair(typeof(T), Name), target.GetType().FullName, target));
                }
            }

            /// <summary>

View on GitHub (pinned to d0c010b051)