{"record":{"id":"c47e582eb904707b","repo":"EllanJiang/GameFramework","slug":"entity-helper-is-invalid-entitymanager","errorCode":null,"errorMessage":"Entity helper is invalid.","messagePattern":"Entity helper is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Entity/EntityManager.cs","lineNumber":236,"sourceCode":"        public void SetResourceManager(IResourceManager resourceManager)\n        {\n            if (resourceManager == null)\n            {\n                throw new GameFrameworkException(\"Resource manager is invalid.\");\n            }\n\n            m_ResourceManager = resourceManager;\n        }\n\n        /// <summary>\n        /// 设置实体辅助器。\n        /// </summary>\n        /// <param name=\"entityHelper\">实体辅助器。</param>\n        public void SetEntityHelper(IEntityHelper entityHelper)\n        {\n            if (entityHelper == null)\n            {\n                throw new GameFrameworkException(\"Entity helper is invalid.\");\n            }\n\n            m_EntityHelper = entityHelper;\n        }\n\n        /// <summary>\n        /// 是否存在实体组。\n        /// </summary>\n        /// <param name=\"entityGroupName\">实体组名称。</param>\n        /// <returns>是否存在实体组。</returns>\n        public bool HasEntityGroup(string entityGroupName)\n        {\n            if (string.IsNullOrEmpty(entityGroupName))\n            {\n                throw new GameFrameworkException(\"Entity group name is invalid.\");\n            }\n\n            return m_EntityGroups.ContainsKey(entityGroupName);","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Entity/EntityManager.cs#L218-L254","documentation":"EntityManager.SetEntityHelper rejects a null IEntityHelper argument. The entity helper performs the actual InstantiateObject/CreateEntity work, so without it no entity can be instantiated; the manager throws a GameFrameworkException at configuration time rather than failing later on the first ShowEntity call.","triggerScenarios":"Calling EntityManager.SetEntityHelper(null), commonly when a custom EntityHelper class was not instantiated, an assembly/type lookup returned null, or DI setup forgot to register the helper.","commonSituations":"Forgetting to create the DefaultEntityHelper (or custom helper) instance in GameEntry, custom helper class failing to compile/attach to a GameObject, or refactorings that dropped the helper construction.","solutions":["Create and pass a concrete IEntityHelper instance (e.g. new DefaultEntityHelper().transform as required) before use.","Ensure the helper GameObject/Component is created if your helper derives from MonoBehaviour and is fetched via GetComponent.","Verify DI/registration code includes the entity helper binding."],"exampleFix":"// before\nm_EntityManager.SetEntityHelper(entityHelper); // entityHelper is null\n\n// after\nDefaultEntityHelper entityHelper = new GameObject(\"Entity Helper\").AddComponent<DefaultEntityHelper>();\nm_EntityManager.SetEntityHelper(entityHelper);","handlingStrategy":"validation","validationCode":"IEntityHelper entityHelper = GetComponent<EntityHelperComponent>();\nif (entityHelper == null) throw new InvalidOperationException(\"EntityHelper must be created before entity manager\");","typeGuard":"bool HasEntityHelper(EntityManager em) => em != null && em.EntityHelper != null;","tryCatchPattern":"try\n{\n    entityManager.SetEntityHelper(entityHelper);\n}\ncatch (GameFrameworkException ex)\n{\n    Debug.LogError($\"Entity helper setup failed: {ex.Message}\");\n}","preventionTips":["Always instantiate a DefaultEntityHelper (or custom helper) during GameEntry setup.","If the helper is a MonoBehaviour, create its GameObject before injecting.","Include the helper in your DI/registration smoke test."],"tags":["gameframework","entity","null-argument","helper"],"backgroundTag":"null-argument","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"}