{"record":{"id":"f991d602384a15af","repo":"EllanJiang/GameFramework","slug":"parent-entity-is-invalid","errorCode":null,"errorMessage":"Parent entity is invalid.","messagePattern":"Parent entity is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Entity/EntityManager.cs","lineNumber":823,"sourceCode":"            EntityInfo parentEntityInfo = GetEntityInfo(parentEntityId);\n            if (parentEntityInfo == null)\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Can not find parent entity '{0}'.\", parentEntityId));\n            }\n\n            return parentEntityInfo.GetChildEntity();\n        }\n\n        /// <summary>\n        /// 获取子实体。\n        /// </summary>\n        /// <param name=\"parentEntity\">要获取子实体的父实体。</param>\n        /// <returns>子实体。</returns>\n        public IEntity GetChildEntity(IEntity parentEntity)\n        {\n            if (parentEntity == null)\n            {\n                throw new GameFrameworkException(\"Parent entity is invalid.\");\n            }\n\n            return GetChildEntity(parentEntity.Id);\n        }\n\n        /// <summary>\n        /// 获取所有子实体。\n        /// </summary>\n        /// <param name=\"parentEntityId\">要获取所有子实体的父实体的实体编号。</param>\n        /// <returns>所有子实体。</returns>\n        public IEntity[] GetChildEntities(int parentEntityId)\n        {\n            EntityInfo parentEntityInfo = GetEntityInfo(parentEntityId);\n            if (parentEntityInfo == null)\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Can not find parent entity '{0}'.\", parentEntityId));\n            }\n","sourceCodeStart":805,"sourceCodeEnd":841,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Entity/EntityManager.cs#L805-L841","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check parentEntity for null before calling GetChildEntity and skip or resolve the lookup first","Ensure the parent entity was successfully obtained (e.g. via GetEntity) and is still alive","Trace why the reference is null — often the entity was removed between acquisition and use"],"exampleFix":"// before\nvar child = entityManager.GetChildEntity(parentEntity);\n// after\nif (parentEntity == null) return null;\nvar child = entityManager.GetChildEntity(parentEntity);","handlingStrategy":"type-guard","validationCode":"if (parentEntity == null) { Debug.LogWarning(\"No parent entity; skip child lookup\"); return; }","typeGuard":"bool IsValidEntity(IEntity e) => e != null && e.Id > 0;","tryCatchPattern":"try { var child = entityManager.GetChildEntity(parentEntity); }\ncatch (GameFrameworkException) { /* null parent; use fallback lookup */ }","preventionTips":["Never cache IEntity references longer than the entity's lifetime","Null-check entity params at method entry","Prefer id-based APIs plus HasEntity when references may go stale"],"tags":["gameframework","entity","null-argument"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}