{"record":{"id":"13010655aaaba5a8","repo":"EllanJiang/GameFramework","slug":"can-not-find-child-entity-0","errorCode":null,"errorMessage":"Can not find child entity '{0}'.","messagePattern":"Can not find child entity '(.+?)'\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Entity/EntityManager.cs","lineNumber":761,"sourceCode":"            foreach (KeyValuePair<int, int> entityBeingLoaded in m_EntitiesBeingLoaded)\n            {\n                m_EntitiesToReleaseOnLoad.Add(entityBeingLoaded.Value);\n            }\n\n            m_EntitiesBeingLoaded.Clear();\n        }\n\n        /// <summary>\n        /// 获取父实体。\n        /// </summary>\n        /// <param name=\"childEntityId\">要获取父实体的子实体的实体编号。</param>\n        /// <returns>子实体的父实体。</returns>\n        public IEntity GetParentEntity(int childEntityId)\n        {\n            EntityInfo childEntityInfo = GetEntityInfo(childEntityId);\n            if (childEntityInfo == null)\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Can not find child entity '{0}'.\", childEntityId));\n            }\n\n            return childEntityInfo.ParentEntity;\n        }\n\n        /// <summary>\n        /// 获取父实体。\n        /// </summary>\n        /// <param name=\"childEntity\">要获取父实体的子实体。</param>\n        /// <returns>子实体的父实体。</returns>\n        public IEntity GetParentEntity(IEntity childEntity)\n        {\n            if (childEntity == null)\n            {\n                throw new GameFrameworkException(\"Child entity is invalid.\");\n            }\n\n            return GetParentEntity(childEntity.Id);","sourceCodeStart":743,"sourceCodeEnd":779,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Entity/EntityManager.cs#L743-L779","documentation":"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.","triggerScenarios":"Calling GetParentEntity with a childEntityId that is not a currently shown entity.","commonSituations":"Child entity was hidden before the parent lookup; stale id after scene teardown; id typo or off-by-one in entity bookkeeping.","solutions":["Verify HasEntity(childEntityId) before calling GetParentEntity","Call GetParentEntity in the same frame the child is known to be alive","Keep a reference to the parent at attach time instead of looking it up later"],"exampleFix":"// before\nIEntity parent = m_EntityComponent.GetParentEntity(childId);\n// after\nif (m_EntityComponent.HasEntity(childId))\n{\n    IEntity parent = m_EntityComponent.GetParentEntity(childId);\n}","handlingStrategy":"validation","validationCode":"if (!entityManager.HasEntity(childEntityId)) return null;","typeGuard":"bool HasParent(int childId) => entityManager.HasEntity(childId);","tryCatchPattern":"try { return GetParentEntity(childId); } catch (GameFrameworkException ex) when (ex.Message.Contains(\"Can not find child entity\")) { return null; }","preventionTips":["Look up parents immediately after the child is shown","Invalidate parent queries when children are hidden","Store parent references at attach time"],"tags":["unity","gameframework","entity","not-found"],"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"}