EllanJiang/GameFramework · error · GameFrameworkException

Can not find child entity

Error message

Can not find child entity '{0}'.

What it means

Thrown by EntityManager.GetParentEntity(int) when no EntityInfo exists for the given childEntityId, i.e. the id does not correspond to any currently registered entity. It signals a lookup miss against the manager's entity table (the entity was never created or has been hidden/destroyed), not a missing parent relationship.

Solutions

  1. Verify HasEntity(childEntityId) before calling GetParentEntity
  2. Call GetParentEntity in the same frame the child is known to be alive
  3. Keep a reference to the parent at attach time instead of looking it up later

Example fix

// before
IEntity parent = m_EntityComponent.GetParentEntity(childId);
// after
if (m_EntityComponent.HasEntity(childId))
{
    IEntity parent = m_EntityComponent.GetParentEntity(childId);
}
Defensive patterns

Strategy: validation

Validate before calling

if (!entityManager.HasEntity(childEntityId)) return null;

Type guard

bool HasParent(int childId) => entityManager.HasEntity(childId);

Try / catch

try { return GetParentEntity(childId); } catch (GameFrameworkException ex) when (ex.Message.Contains("Can not find child entity")) { return null; }

Prevention

When it happens

Trigger: Calling GetParentEntity with a childEntityId that is not a currently shown entity.

Common situations: Child entity was hidden before the parent lookup; stale id after scene teardown; id typo or off-by-one in entity bookkeeping.

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


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/13010655aaaba5a8. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Entity/EntityManager.cs:761

            foreach (KeyValuePair<int, int> entityBeingLoaded in m_EntitiesBeingLoaded)
            {
                m_EntitiesToReleaseOnLoad.Add(entityBeingLoaded.Value);
            }

            m_EntitiesBeingLoaded.Clear();
        }

        /// <summary>
        /// 获取父实体。
        /// </summary>
        /// <param name="childEntityId">要获取父实体的子实体的实体编号。</param>
        /// <returns>子实体的父实体。</returns>
        public IEntity GetParentEntity(int childEntityId)
        {
            EntityInfo childEntityInfo = GetEntityInfo(childEntityId);
            if (childEntityInfo == null)
            {
                throw new GameFrameworkException(Utility.Text.Format("Can not find child entity '{0}'.", childEntityId));
            }

            return childEntityInfo.ParentEntity;
        }

        /// <summary>
        /// 获取父实体。
        /// </summary>
        /// <param name="childEntity">要获取父实体的子实体。</param>
        /// <returns>子实体的父实体。</returns>
        public IEntity GetParentEntity(IEntity childEntity)
        {
            if (childEntity == null)
            {
                throw new GameFrameworkException("Child entity is invalid.");
            }

            return GetParentEntity(childEntity.Id);

View on GitHub (pinned to d0c010b051)