{"record":{"id":"1434ef2ec9307bc8","repo":"egametang/ET","slug":"cant-set-parent-because-parent-isence-is-null-th","errorCode":null,"errorMessage":"cant set parent because parent iSence is null: {this.GetType().FullName} {value.GetType().FullName}","messagePattern":"cant set parent because parent iSence is null: (.+?) (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.core/Scripts/Core/Share/Entity/Entity.cs","lineNumber":206,"sourceCode":"        public Entity Parent\n        {\n            get => this.parent;\n            protected set\n            {\n                if (value == null)\n                {\n                    throw new Exception($\"cant set parent null: {this.GetType().FullName}\");\n                }\n\n                if (value == this)\n                {\n                    throw new Exception($\"cant set parent self: {this.GetType().FullName}\");\n                }\n\n                // 严格限制parent必须要有iSence,也就是说parent必须在数据树上面\n                if (value.IScene == null)\n                {\n                    throw new Exception($\"cant set parent because parent iSence is null: {this.GetType().FullName} {value.GetType().FullName}\");\n                }\n\n                if (this.parent != null) // 之前有parent\n                {\n                    // parent相同，不设置\n                    if (this.parent == value)\n                    {\n                        Log.Error($\"重复设置了Parent: {this.GetType().FullName} parent: {this.parent.GetType().FullName}\");\n                        return;\n                    }\n\n                    this.parent.RemoveChild(this.Id, false);\n                }\n\n                this.parent = value;\n                this.IsComponent = false;\n                this.parent.AddToChildren(this);\n","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.core/Scripts/Core/Share/Entity/Entity.cs#L188-L224","documentation":"Thrown by Entity.Parent setter when the candidate parent's IScene is null — i.e. the target parent is not attached to any scene (not on the data tree). The ECS strictly requires a parent to belong to a scene so children inherit scene membership transitively.","triggerScenarios":"Reparenting onto an entity that was created but never added to a scene; parenting onto an entity whose scene was disposed; parenting onto a just-instantiated Entity before it is attached to a Scene.","commonSituations":"Creating an Entity with `new` / ObjectPool then trying to parent it before calling scene.Add; entities instantiated during deserialization before the scene graph is wired; reparenting after the owning scene was torn down.","solutions":["Add the candidate parent to a scene (via scene.Add / AddChild / AddComponent) before using it as a parent.","Verify `value.IScene != null` before assigning Parent.","Ensure you are not parenting onto an entity from an already-disposed scene."],"exampleFix":"// before\nvar host = ObjectPool.Instance.Fetch(typeof(HostEntity));\nchild.Parent = host;   // host not in any scene yet\n\n// after\nscene.Add(host);\nchild.Parent = host;","handlingStrategy":"validation","validationCode":"if (newParent != null && newParent.IScene != null)\n{\n    entity.Parent = newParent;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Attach the candidate parent to a scene (scene.Add) before parenting.","Verify newParent.IScene != null before reparenting.","Avoid reparenting onto entities from disposed scenes."],"tags":["entity","ecs","parent","scene","core"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}