EllanJiang/GameFramework · error · GameFrameworkException

Parent entity is invalid.

Error message

Parent entity is invalid.

What it means

GameFramework throws this when GetChildEntity(IEntity) is called with a null parent entity reference. The library requires a concrete parent entity object to read its Id from; a null argument is an unrecoverable programming error, so it fails fast with GameFrameworkException instead of returning null.

Solutions

  1. Check parentEntity for null before calling GetChildEntity and skip or resolve the lookup first
  2. Ensure the parent entity was successfully obtained (e.g. via GetEntity) and is still alive
  3. Trace why the reference is null — often the entity was removed between acquisition and use

Example fix

// before
var child = entityManager.GetChildEntity(parentEntity);
// after
if (parentEntity == null) return null;
var child = entityManager.GetChildEntity(parentEntity);
Defensive patterns

Strategy: type-guard

Validate before calling

if (parentEntity == null) { Debug.LogWarning("No parent entity; skip child lookup"); return; }

Type guard

bool IsValidEntity(IEntity e) => e != null && e.Id > 0;

Try / catch

try { var child = entityManager.GetChildEntity(parentEntity); }
catch (GameFrameworkException) { /* null parent; use fallback lookup */ }

Prevention

When it happens

Trigger: Calling entityComponent.GetChildEntity(parentEntity) (or the EntityManager method directly) with parentEntity == null — e.g. a variable that was never assigned, a lookup that returned null, or a cached entity reference that was cleared.

Common situations: Storing entity references that become null after the entity is hidden/deleted; calling before the entity component is initialized; passing the result of an earlier failed GetEntity call without a null check.

Related errors


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

Appendix: source

Thrown at GameFramework/Entity/EntityManager.cs:823

            EntityInfo parentEntityInfo = GetEntityInfo(parentEntityId);
            if (parentEntityInfo == null)
            {
                throw new GameFrameworkException(Utility.Text.Format("Can not find parent entity '{0}'.", parentEntityId));
            }

            return parentEntityInfo.GetChildEntity();
        }

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

            return GetChildEntity(parentEntity.Id);
        }

        /// <summary>
        /// 获取所有子实体。
        /// </summary>
        /// <param name="parentEntityId">要获取所有子实体的父实体的实体编号。</param>
        /// <returns>所有子实体。</returns>
        public IEntity[] GetChildEntities(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)