{"record":{"id":"5b9f9b0006e77a60","repo":"EllanJiang/GameFramework","slug":"can-not-remove-child-entity-which-is-not-exist","errorCode":null,"errorMessage":"Can not remove child entity which is not exist.","messagePattern":"Can not remove child entity which is not exist\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Entity/EntityManager.EntityInfo.cs","lineNumber":131,"sourceCode":"                    results.Add(childEntity);\n                }\n            }\n\n            public void AddChildEntity(IEntity childEntity)\n            {\n                if (m_ChildEntities.Contains(childEntity))\n                {\n                    throw new GameFrameworkException(\"Can not add child entity which is already exist.\");\n                }\n\n                m_ChildEntities.Add(childEntity);\n            }\n\n            public void RemoveChildEntity(IEntity childEntity)\n            {\n                if (!m_ChildEntities.Remove(childEntity))\n                {\n                    throw new GameFrameworkException(\"Can not remove child entity which is not exist.\");\n                }\n            }\n        }\n    }\n}\n","sourceCodeStart":113,"sourceCodeEnd":137,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Entity/EntityManager.EntityInfo.cs#L113-L137","documentation":"RemoveChildEntity removes a child entity from the entity's child list and throws GameFrameworkException if List.Remove returns false, i.e. the child is not attached to this entity. Called by DetachEntity when detaching an entity that is not actually a child of the given parent.","triggerScenarios":"Calling DetachEntity for an entity whose parent is a different entity or null; detaching twice; stale parent references after hierarchy changes.","commonSituations":"Teardown code detaching all entities from a parent that was already cleared; wrong parent id passed to DetachEntity; concurrent hide/detach removing the child before your detach runs.","solutions":["Verify the child is currently attached to this parent before detaching (GetParentEntity check).","Make detach/cleanup idempotent with an existence check.","Catch GameFrameworkException in bulk teardown loops and continue.","Fix ordering so hide/detach logic runs only once per entity."],"exampleFix":"// before\nentityManager.DetachEntity(childId, parentId); // throws if not a child\n// after\nif (entityManager.GetParentEntity(childId) == parentId)\n{\n    entityManager.DetachEntity(childId, parentId);\n}","handlingStrategy":"validation","validationCode":"if (entityManager.GetParentEntity(childId) != parentId) return;\nentityManager.DetachEntity(childId, parentId);","typeGuard":null,"tryCatchPattern":"try { entityManager.DetachEntity(childId, parentId); }\ncatch (GameFrameworkException ex) { Log.Warning(\"Skip detach, not a child: {0}\", ex.Message); }","preventionTips":["Verify parent-child relation before detaching","Write idempotent teardown loops that tolerate already-detached entities","Keep hide/detach ordering single-shot per entity","Refresh stale parent references after hierarchy changes"],"tags":["csharp","gameframework","entity","not-found","hierarchy"],"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"}