{"record":{"id":"df9817f91ffe4121","repo":"egametang/ET","slug":"cant-set-parent-null-this-gettype-fullname","errorCode":null,"errorMessage":"cant set parent null: {this.GetType().FullName}","messagePattern":"cant set parent null: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.core/Scripts/Core/Share/Entity/Entity.cs","lineNumber":195,"sourceCode":"\n        [MemoryPackIgnore]\n        [BsonIgnore]\n        public bool IsDisposed => this.InstanceId == 0;\n        \n        [AllowEntityMember]\n        private Entity parent;\n\n        // 可以改变parent，但是不能设置为null\n        [MemoryPackIgnore]\n        [BsonIgnore]\n        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                    {","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.core/Scripts/Core/Share/Entity/Entity.cs#L177-L213","documentation":"Thrown by the Entity.Parent setter when the new parent is null. The ECS forbids detaching an entity into a null parent — every entity must live in the scene tree. To remove an entity, call Dispose()/Remove(), not `entity.Parent = null`.","triggerScenarios":"Assigning `entity.Parent = null`; reparenting logic that falls back to null on a missing target; a deserialization path that receives a null parent reference; code copying a parent variable that turned out null.","commonSituations":"Mistaking Detach semantics (you expected Parent=null to detach); parent lookup returns null because the target entity was already disposed or not added to a scene; refactoring that moved the parent assignment into a helper that can be passed null.","solutions":["To remove an entity from its parent, call Dispose() or parent.RemoveChild/RemoveComponent — never assign Parent=null.","Null-check the candidate parent before assigning and bail out or create it in a scene first.","Ensure the target parent entity is itself attached to a scene before reparenting onto it."],"exampleFix":"// before\nentity.Parent = foundParent;   // foundParent may be null\n\n// after\nif (foundParent == null)\n{\n    Log.Error(\"reparent target missing, keeping current parent\");\n    return;\n}\nentity.Parent = foundParent;","handlingStrategy":"validation","validationCode":"if (newParent != null)\n{\n    entity.Parent = newParent;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never assign Parent=null; use Dispose/Remove to detach.","Null-check candidate parents before assignment.","Ensure the target is attached to a scene."],"tags":["entity","ecs","parent","core"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}