{"record":{"id":"41b87340b926f0cb","repo":"EllanJiang/GameFramework","slug":"resource-manager-is-invalid-entitymanager","errorCode":null,"errorMessage":"Resource manager is invalid.","messagePattern":"Resource manager is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Entity/EntityManager.cs","lineNumber":222,"sourceCode":"        public void SetObjectPoolManager(IObjectPoolManager objectPoolManager)\n        {\n            if (objectPoolManager == null)\n            {\n                throw new GameFrameworkException(\"Object pool manager is invalid.\");\n            }\n\n            m_ObjectPoolManager = objectPoolManager;\n        }\n\n        /// <summary>\n        /// 设置资源管理器。\n        /// </summary>\n        /// <param name=\"resourceManager\">资源管理器。</param>\n        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        }","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Entity/EntityManager.cs#L204-L240","documentation":"EntityManager.SetResourceManager rejects a null IResourceManager argument. The entity system loads entity assets through the resource manager, so a null reference would make ShowEntity and related flows fail later; the framework throws immediately to fail fast at setup time.","triggerScenarios":"Calling EntityManager.SetResourceManager(null), usually when the ResourceComponent was not created/initialized yet or the lookup that produced the reference returned null.","commonSituations":"Wrong initialization order in GameEntry (EntityComponent initialized before ResourceComponent), resource component retrieval by wrong type or name, or stripped-down framework builds that omit the resource module.","solutions":["Initialize the ResourceComponent (IResourceManager) before calling SetResourceManager.","Verify the code fetching the resource manager actually returns a live instance.","Reorder your bootstrap sequence: resource manager -> object pool manager -> entity helper -> entity manager wiring."],"exampleFix":"// before\nm_EntityManager.SetResourceManager(maybeResourceManager); // may be null\n\n// after\nIResourceManager resourceManager = GameEntry.GetComponent<ResourceComponent>();\nDebugger.Assert(resourceManager != null, \"ResourceManager missing\");\nm_EntityManager.SetResourceManager(resourceManager);","handlingStrategy":"validation","validationCode":"IResourceManager resourceManager = GameEntry.GetComponent<ResourceComponent>();\nif (resourceManager == null) throw new InvalidOperationException(\"ResourceComponent must be initialized before entity manager\");","typeGuard":"bool HasResourceManager(EntityManager em) => em != null && em.ResourceManager != null;","tryCatchPattern":"try\n{\n    entityManager.SetResourceManager(resourceManager);\n}\ncatch (GameFrameworkException ex)\n{\n    Debug.LogError($\"Entity init failed: {ex.Message}\");\n}","preventionTips":["Wire ResourceComponent before EntityComponent in bootstrap.","Assert retrieved component references are non-null before injecting.","Keep an ordered initialization checklist for framework managers."],"tags":["gameframework","entity","null-argument","initialization"],"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"}