{"record":{"id":"7ca12bbe8a35b1b4","repo":"EllanJiang/GameFramework","slug":"you-must-set-object-pool-manager-first","errorCode":null,"errorMessage":"You must set object pool manager first.","messagePattern":"You must set object pool manager first\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Entity/EntityManager.cs","lineNumber":336,"sourceCode":"        /// <param name=\"instanceExpireTime\">实体实例对象池对象过期秒数。</param>\n        /// <param name=\"instancePriority\">实体实例对象池的优先级。</param>\n        /// <param name=\"entityGroupHelper\">实体组辅助器。</param>\n        /// <returns>是否增加实体组成功。</returns>\n        public bool AddEntityGroup(string entityGroupName, float instanceAutoReleaseInterval, int instanceCapacity, float instanceExpireTime, int instancePriority, IEntityGroupHelper entityGroupHelper)\n        {\n            if (string.IsNullOrEmpty(entityGroupName))\n            {\n                throw new GameFrameworkException(\"Entity group name is invalid.\");\n            }\n\n            if (entityGroupHelper == null)\n            {\n                throw new GameFrameworkException(\"Entity group helper is invalid.\");\n            }\n\n            if (m_ObjectPoolManager == null)\n            {\n                throw new GameFrameworkException(\"You must set object pool manager first.\");\n            }\n\n            if (HasEntityGroup(entityGroupName))\n            {\n                return false;\n            }\n\n            m_EntityGroups.Add(entityGroupName, new EntityGroup(entityGroupName, instanceAutoReleaseInterval, instanceCapacity, instanceExpireTime, instancePriority, entityGroupHelper, m_ObjectPoolManager));\n\n            return true;\n        }\n\n        /// <summary>\n        /// 是否存在实体。\n        /// </summary>\n        /// <param name=\"entityId\">实体编号。</param>\n        /// <returns>是否存在实体。</returns>\n        public bool HasEntity(int entityId)","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Entity/EntityManager.cs#L318-L354","documentation":"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.","triggerScenarios":"Calling AddEntityGroup before EntityManager initialization completes; using a manually constructed EntityManager without calling SetObjectPoolManager; Unity EntityComponent missing its ObjectPoolComponent/manager reference.","commonSituations":"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.","solutions":["Call SetObjectPoolManager with a valid IObjectPoolManager before AddEntityGroup","In Unity, ensure the ObjectPool component is present on the same GameObject and wired into EntityComponent","Reorder initialization so the object pool manager is set up before entity groups are registered"],"exampleFix":"// before\nvar entity = new EntityManager();\nentity.AddEntityGroup(\"Player\", 1f, 8, 60f, 0, helper);\n// after\nvar entity = new EntityManager();\nentity.SetObjectPoolManager(objectPoolComponent.ObjectPoolManager);\nentity.AddEntityGroup(\"Player\", 1f, 8, 60f, 0, helper);","handlingStrategy":"try-catch","validationCode":"if (entityManager.ObjectPoolManager == null) { Log.Error(\"Set object pool manager before adding entity groups\"); return; }","typeGuard":"bool IsEntityManagerReady(EntityManager em) => em.ObjectPoolManager != null;","tryCatchPattern":"try { entityManager.AddEntityGroup(name, interval, capacity, expire, priority, helper); } catch (GameFrameworkException ex) { Log.Error(ex, \"Object pool manager not set; init order wrong\"); }","preventionTips":["Enforce init order: create/set object pool manager before entity module use","In Unity keep the ObjectPool component above/with EntityComponent and verify references","Centralize framework initialization in one entry point so dependencies are always injected in order"],"tags":["gameframework","entity","initialization-order"],"backgroundTag":"missing-dependency","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}