EllanJiang/GameFramework · error · GameFrameworkException
Object is invalid.
Error message
Object is invalid.
What it means
Object<T>.Create is the internal factory that wraps a pooled object for ObjectPoolManager. It requires a non-null obj and throws 'Object is invalid.' otherwise. This is the inner guard behind ObjectPool.Register, so the pool never holds entries with null payloads.
Solutions
- Null-check the object before calling Register and abort or log the load failure
- Ensure the object producer (loader, factory, spawner) cannot silently return null
- Fix the upstream creation code that produced null
Example fix
// before
objectPool.Register(loadedObject, false); // loadedObject may be null
// after
if (loadedObject != null) { objectPool.Register(loadedObject, false); } Defensive patterns
Strategy: validation
Validate before calling
if (obj == null) { Log.Error("Cannot register null object"); return; }
objectPool.Register(obj, spawned); Type guard
bool IsRegisterable<T>(T obj) where T : class => obj != null;
Try / catch
try { objectPool.Register(obj, spawned); }
catch (GameFrameworkException ex) { Log.Error("Invalid object for pool: {0}", ex.Message); } Prevention
- Guard all producers of pooled objects for null
- Never pass raw load results directly to Register
- Use ArgumentNullException in your own factories
When it happens
Trigger: Calling ObjectPool.Register(obj, spawned) with a null obj, which reaches Object<T>.Create and throws; also any direct use of Object<T>.Create with null.
Common situations: Resource load failure producing null which is then registered; API returning null on cache miss being passed straight to Register; generic T being a reference type with an uninitialized variable.
Related errors
- Target ' ' is invalid.
- Object is invalid.
- Release object filter callback is invalid.
- Results is invalid.
- Object type is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/c86c7285cdafe653.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/ObjectPool/ObjectPoolManager.Object.cs:127
public int SpawnCount
{
get
{
return m_SpawnCount;
}
}
/// <summary>
/// 创建内部对象。
/// </summary>
/// <param name="obj">对象。</param>
/// <param name="spawned">对象是否已被获取。</param>
/// <returns>创建的内部对象。</returns>
public static Object<T> Create(T obj, bool spawned)
{
if (obj == null)
{
throw new GameFrameworkException("Object is invalid.");
}
Object<T> internalObject = ReferencePool.Acquire<Object<T>>();
internalObject.m_Object = obj;
internalObject.m_SpawnCount = spawned ? 1 : 0;
if (spawned)
{
obj.OnSpawn();
}
return internalObject;
}
/// <summary>
/// 清理内部对象。
/// </summary>
public void Clear()
{View on GitHub (pinned to d0c010b051)