EllanJiang/GameFramework · error · GameFrameworkException
Can not find parent entity
Error message
Can not find parent entity '{0}'. What it means
Thrown by EntityManager.GetChildEntityCount(int) when GetEntityInfo(parentEntityId) returns null, meaning the parent entity id is not present in the manager. The count operation cannot proceed without a registered parent entity; ensure the entity exists before querying its children.
Solutions
- Check HasEntity(parentEntityId) before calling GetChildEntityCount
- Re-fetch fresh entity ids instead of caching them across hide/show cycles
- Wrap in try-catch if the parent may legitimately disappear mid-frame
Example fix
// before
int count = m_EntityComponent.GetChildEntityCount(parentId);
// after
int count = m_EntityComponent.HasEntity(parentId)
? m_EntityComponent.GetChildEntityCount(parentId)
: 0; Defensive patterns
Strategy: validation
Validate before calling
if (!entityManager.HasEntity(parentEntityId)) return 0;
Type guard
bool ParentAlive(int id) => entityManager.HasEntity(id);
Try / catch
try { return GetChildEntityCount(parentId); } catch (GameFrameworkException ex) when (ex.Message.Contains("Can not find parent entity")) { return 0; } Prevention
- Re-read parent ids each frame instead of caching
- Hide children together with parents to keep counts coherent
- Check HasEntity before any parent-based query
When it happens
Trigger: Calling GetChildEntityCount with a parentEntityId not present among shown entities.
Common situations: Parent hidden or destroyed before querying child count; stale id cached across scene loads; iterating ids from an old snapshot of shown entities.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Can not find entity ' '.
- Can not find child entity
- Entity group ' ' not exists specified entity '[ ] '.
- Can not remove child entity which is not exist.
- Entity id ' ' is already exist.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/85586d9a24241a1d.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Entity/EntityManager.cs:792
if (childEntity == null)
{
throw new GameFrameworkException("Child entity is invalid.");
}
return GetParentEntity(childEntity.Id);
}
/// <summary>
/// 获取子实体数量。
/// </summary>
/// <param name="parentEntityId">要获取子实体数量的父实体的实体编号。</param>
/// <returns>子实体数量。</returns>
public int GetChildEntityCount(int parentEntityId)
{
EntityInfo parentEntityInfo = GetEntityInfo(parentEntityId);
if (parentEntityInfo == null)
{
throw new GameFrameworkException(Utility.Text.Format("Can not find parent entity '{0}'.", parentEntityId));
}
return parentEntityInfo.ChildEntityCount;
}
/// <summary>
/// 获取子实体。
/// </summary>
/// <param name="parentEntityId">要获取子实体的父实体的实体编号。</param>
/// <returns>子实体。</returns>
public IEntity GetChildEntity(int parentEntityId)
{
EntityInfo parentEntityInfo = GetEntityInfo(parentEntityId);
if (parentEntityInfo == null)
{
throw new GameFrameworkException(Utility.Text.Format("Can not find parent entity '{0}'.", parentEntityId));
}
View on GitHub (pinned to d0c010b051)