{"record":{"id":"4afcf5e06f840c29","repo":"EllanJiang/GameFramework","slug":"entity-id-0-is-already-exist","errorCode":null,"errorMessage":"Entity id '{0}' is already exist.","messagePattern":"Entity id '(.+?)' is already exist\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Entity/EntityManager.cs","lineNumber":632,"sourceCode":"\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))\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Entity id '{0}' is already exist.\", entityId));\n            }\n\n            if (IsLoadingEntity(entityId))\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Entity '{0}' is already being loaded.\", entityId));\n            }\n\n            EntityGroup entityGroup = (EntityGroup)GetEntityGroup(entityGroupName);\n            if (entityGroup == null)\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Entity group '{0}' is not exist.\", entityGroupName));\n            }\n\n            EntityInstanceObject entityInstanceObject = entityGroup.SpawnEntityInstanceObject(entityAssetName);\n            if (entityInstanceObject == null)\n            {\n                int serialId = ++m_Serial;\n                m_EntitiesBeingLoaded.Add(entityId, serialId);","sourceCodeStart":614,"sourceCodeEnd":650,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Entity/EntityManager.cs#L614-L650","documentation":"EntityManager.ShowEntity enforces that each entity id is unique while shown. If HasEntity(entityId) is true, the id is already in use by a live entity, so it throws. Entity ids are caller-supplied serial numbers and must not collide.","triggerScenarios":"Calling ShowEntity with an entityId that already belongs to an existing (not yet hidden) entity.","commonSituations":"Reusing serial id counters after domain reload; showing the same logical entity twice (e.g., double click spawning a unit); restoring a scene without hiding previous entities; serial id generator reset.","solutions":["Use a strictly increasing unique serial id generator (e.g., m_Serial++) per show call","Hide the existing entity with that id before re-showing it","Check HasEntity(entityId) before calling ShowEntity and skip or error out gracefully"],"exampleFix":"// before\nint id = 1001;\nm_EntityComponent.ShowEntity(id, \"Player\", \"PlayerGroup\", null); // called twice\n// after\nif (!m_EntityComponent.HasEntity(id))\n{\n    m_EntityComponent.ShowEntity(id, \"Player\", \"PlayerGroup\", null);\n}","handlingStrategy":"validation","validationCode":"if (entityManager.HasEntity(entityId)) return; // already shown","typeGuard":"bool CanShow(int id) => !entityManager.HasEntity(id) && !entityManager.IsLoadingEntity(id);","tryCatchPattern":"try { ShowEntity(id, asset, group, userData); } catch (GameFrameworkException ex) when (ex.Message.Contains(\"is already exist\")) { Debug.LogWarning($\"Entity {id} already shown, skipping\"); }","preventionTips":["Use a single central serial id generator","Never reset id counters mid-session","Check HasEntity before every ShowEntity"],"tags":["unity","gameframework","entity","duplicate-id"],"backgroundTag":"entity-not-found","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}