EllanJiang/GameFramework · error · GameFrameworkException

Object type is invalid.

Error message

Object type is invalid.

What it means

ObjectPoolManager.HasObjectPool(Type objectType) validates that the type is non-null and derives from ObjectBase. A null type cannot form the pool's TypeNamePair key, so the manager throws 'Object type is invalid.' as the first of two validation failures.

Solutions

  1. Pass a concrete non-null type, e.g. typeof(MyItem) or item.GetType().
  2. Fix the reflection call so Type.GetType succeeds (use assembly-qualified names) and check the result before use.
  3. Use the generic HasObjectPool<T>() overload when the type is known at compile time.

Example fix

// before
Type t = Type.GetType("MyItem"); // returns null if not found
poolManager.HasObjectPool(t);
// after
poolManager.HasObjectPool(typeof(MyItem));
Defensive patterns

Strategy: validation

Validate before calling

if (objectType != null && typeof(ObjectBase).IsAssignableFrom(objectType))
{
    bool has = poolManager.HasObjectPool(objectType);
}

Type guard

bool IsPoolableType(Type t) => t != null && typeof(ObjectBase).IsAssignableFrom(t);

Try / catch

try { poolManager.HasObjectPool(objectType); }
catch (GameFrameworkException ex) { Debug.LogError($"Invalid pool type query: {ex.Message}"); }

Prevention

When it happens

Trigger: Calling gameFrameworkObjectPoolComponent / ObjectPoolManager.HasObjectPool(null); a Type variable resolved via reflection (Type.GetType) that returned null because the type name string was wrong or assembly not loaded.

Common situations: Reflection lookups with misspelled assembly-qualified names; generic helpers where typeof(T) was replaced by a nullable Type field left unset; config-driven pool type strings not resolvable at runtime.

Related errors


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

Appendix: source

Thrown at GameFramework/ObjectPool/ObjectPoolManager.cs:105

        /// 检查是否存在对象池。
        /// </summary>
        /// <typeparam name="T">对象类型。</typeparam>
        /// <returns>是否存在对象池。</returns>
        public bool HasObjectPool<T>() where T : ObjectBase
        {
            return InternalHasObjectPool(new TypeNamePair(typeof(T)));
        }

        /// <summary>
        /// 检查是否存在对象池。
        /// </summary>
        /// <param name="objectType">对象类型。</param>
        /// <returns>是否存在对象池。</returns>
        public bool HasObjectPool(Type objectType)
        {
            if (objectType == null)
            {
                throw new GameFrameworkException("Object type is invalid.");
            }

            if (!typeof(ObjectBase).IsAssignableFrom(objectType))
            {
                throw new GameFrameworkException(Utility.Text.Format("Object type '{0}' is invalid.", objectType.FullName));
            }

            return InternalHasObjectPool(new TypeNamePair(objectType));
        }

        /// <summary>
        /// 检查是否存在对象池。
        /// </summary>
        /// <typeparam name="T">对象类型。</typeparam>
        /// <param name="name">对象池名称。</param>
        /// <returns>是否存在对象池。</returns>
        public bool HasObjectPool<T>(string name) where T : ObjectBase
        {

View on GitHub (pinned to d0c010b051)