{"record":{"id":"77699bda5cf795fb","repo":"EllanJiang/GameFramework","slug":"you-must-set-resource-manager-first-entitymanager","errorCode":null,"errorMessage":"You must set resource manager first.","messagePattern":"You must set resource manager first\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"critical","filePath":"GameFramework/Entity/EntityManager.cs","lineNumber":612,"sourceCode":"        /// <param name=\"userData\">用户自定义数据。</param>\n        public void ShowEntity(int entityId, string entityAssetName, string entityGroupName, object userData)\n        {\n            ShowEntity(entityId, entityAssetName, entityGroupName, Constant.DefaultPriority, userData);\n        }\n\n        /// <summary>\n        /// 显示实体。\n        /// </summary>\n        /// <param name=\"entityId\">实体编号。</param>\n        /// <param name=\"entityAssetName\">实体资源名称。</param>\n        /// <param name=\"entityGroupName\">实体组名称。</param>\n        /// <param name=\"priority\">加载实体资源的优先级。</param>\n        /// <param name=\"userData\">用户自定义数据。</param>\n        public void ShowEntity(int entityId, string entityAssetName, string entityGroupName, int priority, object userData)\n        {\n            if (m_ResourceManager == null)\n            {\n                throw new GameFrameworkException(\"You must set resource manager first.\");\n            }\n\n            if (m_EntityHelper == null)\n            {\n                throw new GameFrameworkException(\"You must set entity helper first.\");\n            }\n\n            if (string.IsNullOrEmpty(entityAssetName))\n            {\n                throw new GameFrameworkException(\"Entity asset name is invalid.\");\n            }\n\n            if (string.IsNullOrEmpty(entityGroupName))\n            {\n                throw new GameFrameworkException(\"Entity group name is invalid.\");\n            }\n\n            if (HasEntity(entityId))","sourceCodeStart":594,"sourceCodeEnd":630,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Entity/EntityManager.cs#L594-L630","documentation":"EntityManager.ShowEntity throws \"You must set resource manager first.\" when the internal m_ResourceManager is null. The ResourceManager must be injected via SetResourceManager before any entity can be shown, since ShowEntity needs it to load the entity asset. This is an initialization-order error, not a bad argument.","triggerScenarios":"Calling ShowEntity (directly or via the Unity EntityComponent) before SetResourceManager was called — e.g. showing an entity in Awake before framework initialization completes, or forgetting to add the resource component that wires it up.","commonSituations":"GameEntry/EF-initialization ordering mistakes in Unity where EntityComponent's Awake runs before ResourceComponent sets the manager; custom bootstrap code that skips SetResourceManager.","solutions":["Call entityManager.SetResourceManager(resourceManager) during framework startup, before any ShowEntity call.","In Unity GameFramework, ensure the ResourceComponent exists in the scene and initializes before EntityComponent shows entities (defer ShowEntity to a Start/after-init callback).","Check your GameEntry.Procedure initialization flow: resource manager must be set in the InitResources/procedure chain before entity show procedures run."],"exampleFix":"// before\nentityManager.ShowEntity(entityId, assetName, groupName); // throws if not initialized\n// after\nentityManager.SetResourceManager(resourceManager);\nentityManager.SetEntityHelper(entityHelper);\nentityManager.ShowEntity(entityId, assetName, groupName);","handlingStrategy":"try-catch","validationCode":"if (entityManager == null || !entityManager.IsAvailable) // check framework init state\n    return; // or defer the ShowEntity call until initialization completes","typeGuard":"bool CanShowEntities(EntityManager em) => em != null; // plus verify SetResourceManager was called in your bootstrap","tryCatchPattern":"try { entityManager.ShowEntity(entityId, assetName, groupName); }\ncatch (GameFrameworkException ex) when (ex.Message.Contains(\"set resource manager first\"))\n{\n    // queue or defer the request until framework init finishes\n}","preventionTips":["Always call SetResourceManager during framework startup before any gameplay code runs.","In Unity, ensure ResourceComponent initializes before procedures that show entities.","Gate entity show calls behind a 'framework ready' flag set after initialization."],"tags":["gameframework","entity","initialization-order","missing-dependency"],"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"}