{"record":{"id":"175796f285b15fd8","repo":"egametang/ET","slug":"iscene-cant-set-null-this-gettype-fullname","errorCode":null,"errorMessage":"iScene cant set null: {this.GetType().FullName}","messagePattern":"iScene cant set null: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.core/Scripts/Core/Share/Entity/Entity.cs","lineNumber":327,"sourceCode":"        [BsonId]\n        public long Id { get; protected set; }\n\n        [BsonIgnore]\n        protected IScene iScene;\n\n        [MemoryPackIgnore]\n        [BsonIgnore]\n        public IScene IScene\n        {\n            get\n            {\n                return this.iScene;\n            }\n            protected set\n            {\n                if (value == null)\n                {\n                    throw new Exception($\"iScene cant set null: {this.GetType().FullName}\");\n                }\n\n                if (this.iScene == value)\n                {\n                    return;\n                }\n\n                if (this.iScene != null)\n                {\n                    this.iScene = value;\n                    return;\n                }\n\n                this.iScene = value;\n                \n                if (this.InstanceId == 0)\n                {\n                    this.InstanceId = iScene.Fiber.NewInstanceId();","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.core/Scripts/Core/Share/Entity/Entity.cs#L309-L345","documentation":"Thrown by the Entity.IScene setter when assigning null. Every entity must belong to exactly one scene; null is never valid. Removing an entity from its scene is done by Dispose, not by clearing IScene.","triggerScenarios":"Directly assigning `entity.IScene = null`; a rebind routine that nulls the scene reference on cleanup; deserialization encountering a null scene reference.","commonSituations":"Tearing down a scene but nulling the property instead of disposing entities; reparent helper that resets scene to null as a reset step.","solutions":["Never assign null to IScene; remove the entity via Dispose() instead.","Null-check any candidate scene before assigning.","Confirm the target scene object is constructed and valid before binding."],"exampleFix":"// before\nentity.IScene = newScene;   // newScene may be null\n\n// after\nif (newScene == null) throw new InvalidOperationException(\"scene required\");\nentity.IScene = newScene;","handlingStrategy":"validation","validationCode":"if (newScene != null)\n{\n    entity.IScene = newScene;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never assign null to IScene; dispose to remove.","Validate the scene object before binding.","Tear scenes down via Dispose, not by clearing references."],"tags":["entity","ecs","scene","core"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}