{"record":{"id":"347f373cd0a2af4a","repo":"egametang/ET","slug":"entity-already-has-component-type-fullname","errorCode":null,"errorMessage":"entity already has component: {type.FullName}","messagePattern":"entity already has component: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.core/Scripts/Core/Share/Entity/Entity.cs","lineNumber":677,"sourceCode":"            return component;\n        }\n\n        private static Entity Create(Type type, bool isFromPool)\n        {\n            Entity component = (Entity) ObjectPool.Fetch(type, isFromPool);\n            component.IsFromPool = true;\n            component.IsNoDeserializeSystem = true;\n            component.Id = 0;\n            return component;\n        }\n\n        protected Entity CreateComponent(Type type, long id, bool isFromPool)\n        {\n            this.CheckThread();\n            \n            if (this.components != null && this.components.ContainsKey(this.GetComponentLongHashCode(type)))\n            {\n                throw new Exception($\"entity already has component: {type.FullName}\");\n            }\n\n            Entity component = Create(type, isFromPool);\n            component.Id = id;\n            component.ComponentParent = this;\n            return component;\n        }\n\n        protected Entity CreateChild(Type type, long id, bool isFromPool)\n        {\n            this.CheckThread();\n            \n            Entity component = Create(type, isFromPool);\n            component.Id = id;\n            component.Parent = this;\n            return component;\n        }\n","sourceCodeStart":659,"sourceCodeEnd":695,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.core/Scripts/Core/Share/Entity/Entity.cs#L659-L695","documentation":"Thrown by Entity.CreateComponent when the entity already contains a component of the given type. The ECS allows at most one component per concrete type per entity; adding a duplicate type is rejected because the lookup map already holds its LongHashCode.","triggerScenarios":"Calling CreateComponent for a type already in components; AddComponent path that internally calls CreateComponent for an existing type; deserialization adding a component that already exists on the entity.","commonSituations":"Calling AddComponent twice for the same type without removing first; InitSystems/AwakeSystems running twice; reload/restart logic re-initializing an entity.","solutions":["Before adding, check GetComponent(type) and RemoveComponent first if a fresh instance is desired.","Make init/idempotent so AddComponent for that type runs only once.","Use GetComponentOrNull to test existence rather than assuming absence."],"exampleFix":"// before\nentity.AddComponent(typeof(MyComp), fromPool);\n\n// after\nif (entity.GetComponentOrNull(typeof(MyComp)) == null)\n{\n    entity.AddComponent(typeof(MyComp), fromPool);\n}","handlingStrategy":"validation","validationCode":"if (entity.GetComponentOrNull(type) == null)\n{\n    entity.AddComponent(type, isFromPool);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check GetComponentOrNull before CreateComponent/AddComponent.","RemoveComponent before re-adding a fresh instance.","Make init/idempotent so duplicate adds are impossible."],"tags":["entity","ecs","component","duplicate","core"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}