EllanJiang/GameFramework · error · GameFrameworkException

You must set object pool manager first.

Error message

You must set object pool manager first.

What it means

EntityManager.AddEntityGroup throws GameFrameworkException when m_ObjectPoolManager is null, meaning SetObjectPoolManager was never called (or the EntityComponent's ObjectPoolManager reference is missing). Entity groups create their object pools through the object pool manager, so it must be injected first.

Solutions

  1. Call SetObjectPoolManager with a valid IObjectPoolManager before AddEntityGroup
  2. In Unity, ensure the ObjectPool component is present on the same GameObject and wired into EntityComponent
  3. Reorder initialization so the object pool manager is set up before entity groups are registered

Example fix

// before
var entity = new EntityManager();
entity.AddEntityGroup("Player", 1f, 8, 60f, 0, helper);
// after
var entity = new EntityManager();
entity.SetObjectPoolManager(objectPoolComponent.ObjectPoolManager);
entity.AddEntityGroup("Player", 1f, 8, 60f, 0, helper);
Defensive patterns

Strategy: try-catch

Validate before calling

if (entityManager.ObjectPoolManager == null) { Log.Error("Set object pool manager before adding entity groups"); return; }

Type guard

bool IsEntityManagerReady(EntityManager em) => em.ObjectPoolManager != null;

Try / catch

try { entityManager.AddEntityGroup(name, interval, capacity, expire, priority, helper); } catch (GameFrameworkException ex) { Log.Error(ex, "Object pool manager not set; init order wrong"); }

Prevention

When it happens

Trigger: Calling AddEntityGroup before EntityManager initialization completes; using a manually constructed EntityManager without calling SetObjectPoolManager; Unity EntityComponent missing its ObjectPoolComponent/manager reference.

Common situations: Custom bootstrap code that adds entity groups too early in the init order; removing or renaming the ObjectPool component so the serialized reference is lost; unit tests instantiating EntityManager directly.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

Thrown at GameFramework/Entity/EntityManager.cs:336

        /// <param name="instanceExpireTime">实体实例对象池对象过期秒数。</param>
        /// <param name="instancePriority">实体实例对象池的优先级。</param>
        /// <param name="entityGroupHelper">实体组辅助器。</param>
        /// <returns>是否增加实体组成功。</returns>
        public bool AddEntityGroup(string entityGroupName, float instanceAutoReleaseInterval, int instanceCapacity, float instanceExpireTime, int instancePriority, IEntityGroupHelper entityGroupHelper)
        {
            if (string.IsNullOrEmpty(entityGroupName))
            {
                throw new GameFrameworkException("Entity group name is invalid.");
            }

            if (entityGroupHelper == null)
            {
                throw new GameFrameworkException("Entity group helper is invalid.");
            }

            if (m_ObjectPoolManager == null)
            {
                throw new GameFrameworkException("You must set object pool manager first.");
            }

            if (HasEntityGroup(entityGroupName))
            {
                return false;
            }

            m_EntityGroups.Add(entityGroupName, new EntityGroup(entityGroupName, instanceAutoReleaseInterval, instanceCapacity, instanceExpireTime, instancePriority, entityGroupHelper, m_ObjectPoolManager));

            return true;
        }

        /// <summary>
        /// 是否存在实体。
        /// </summary>
        /// <param name="entityId">实体编号。</param>
        /// <returns>是否存在实体。</returns>
        public bool HasEntity(int entityId)

View on GitHub (pinned to d0c010b051)