EllanJiang/GameFramework · error · GameFrameworkException
Can not add child entity which is already exist.
Error message
Can not add child entity which is already exist.
What it means
AddChildEntity attaches a child entity to this entity's child list and throws if the child is already in m_ChildEntities. Duplicate children would break detach counts and hierarchy iteration, so the library fails fast instead of silently ignoring. Raised from AttachEntity when the same entity is attached twice.
Solutions
- Check the child's existing parent before attaching (skip if already attached to this parent).
- Make attach calls idempotent: guard with your own child-list check or a bool flag.
- Detach first, then re-attach, when re-parenting intentionally.
- Catch GameFrameworkException if duplicate attach is acceptable in your flow.
Example fix
// before
entityManager.AttachEntity(childId, parentId);
entityManager.AttachEntity(childId, parentId); // throws on second call
// after
if (entityManager.GetParentEntity(childId) != parentId)
{
entityManager.AttachEntity(childId, parentId);
} Defensive patterns
Strategy: validation
Validate before calling
if (entityManager.GetParentEntity(childId) == parentId) return; // already attached entityManager.AttachEntity(childId, parentId);
Try / catch
try { entityManager.AttachEntity(childId, parentId); }
catch (GameFrameworkException ex) { Log.Warning("Already attached: {0}", ex.Message); } Prevention
- Check current parent before attaching
- Make attach idempotent with a state flag
- Debounce UI events that trigger attach
- Detach before re-attaching to the same parent
When it happens
Trigger: Calling EntityManager.AttachEntity(childEntityId, parentId) twice for the same pair, or attaching an entity that is already a child of that parent.
Common situations: Retry logic that re-issues AttachEntity after an ambiguous failure; UI/code paths where an attach event fires twice (e.g. double-click); missing state check when re-parenting within the same parent.
Related errors
- Can not remove child entity which is not exist.
- Entity group ' ' not exists specified entity '[ ] '.
- Entity is invalid.
- Results is invalid.
- Owner is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/4d23e5fd9a571381.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Entity/EntityManager.EntityInfo.cs:121
public void GetChildEntities(List<IEntity> results)
{
if (results == null)
{
throw new GameFrameworkException("Results is invalid.");
}
results.Clear();
foreach (IEntity childEntity in m_ChildEntities)
{
results.Add(childEntity);
}
}
public void AddChildEntity(IEntity childEntity)
{
if (m_ChildEntities.Contains(childEntity))
{
throw new GameFrameworkException("Can not add child entity which is already exist.");
}
m_ChildEntities.Add(childEntity);
}
public void RemoveChildEntity(IEntity childEntity)
{
if (!m_ChildEntities.Remove(childEntity))
{
throw new GameFrameworkException("Can not remove child entity which is not exist.");
}
}
}
}
}
View on GitHub (pinned to d0c010b051)