{"record":{"id":"1b4cad2a850f03af","repo":"stride3d/stride","slug":"the-camera-camera-entity-name-is-already-attached","errorCode":null,"errorMessage":"The camera [{camera.Entity.Name}] is already attached","messagePattern":"The camera \\[(.+?)\\] is already attached","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Engine/Engine/Processors/CameraProcessor.cs","lineNumber":132,"sourceCode":"                }\n            }\n        }\n\n        protected override void OnEntityComponentRemoved(Entity entity, CameraComponent component, CameraComponent data)\n        {\n            if (component.Slot.AttachedCompositor != null)\n                DetachCameraFromSlot(component);\n        }\n\n        private void OnCameraSlotsChanged(object sender, ref FastTrackingCollectionChangedEventArgs e)\n        {\n            cameraSlotsDirty = true;\n        }\n\n        private void AttachCameraToSlot(GraphicsCompositor graphicsCompositor, CameraComponent camera)\n        {\n            if (!camera.Enabled) throw new InvalidOperationException($\"The camera [{camera.Entity.Name}] is disabled and can't be attached\");\n            if (camera.Slot.AttachedCompositor != null) throw new InvalidOperationException($\"The camera [{camera.Entity.Name}] is already attached\");\n\n            for (var i = 0; i < graphicsCompositor.Cameras.Count; ++i)\n            {\n                var slot = graphicsCompositor.Cameras[i];\n                if (slot.Id == camera.Slot.Id)\n                {\n                    if (slot.Camera != null)\n                        throw new InvalidOperationException($\"Unable to attach camera [{camera.Entity.Name}] to the graphics compositor. Another camera, [{slot.Camera.Entity.Name}], is enabled and already attached to this slot.\");\n\n                    slot.Camera = camera;\n                    camera.Slot.AttachedCompositor = graphicsCompositor;\n                    break;\n                }\n            }\n        }\n\n        private static void DetachCameraFromSlot(CameraComponent camera)\n        {","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Engine/Engine/Processors/CameraProcessor.cs#L114-L150","documentation":"CameraProcessor.AttachCameraToSlot throws InvalidOperationException when the CameraComponent's Slot already has an AttachedCompositor, i.e. the camera is already bound to some compositor slot. A camera cannot be attached to more than one slot at a time.","triggerScenarios":"Attaching the same CameraComponent twice (e.g. adding the entity again, re-running setup logic each frame, or reusing one camera component across two GraphicsCompositor slots).","commonSituations":"Re-adding a camera entity to a scene without removing it first; sharing a single camera component between two scene setups; script that calls attach logic every Update instead of once.","solutions":["Check camera.Slot.AttachedCompositor == null before attaching, or skip if already attached","Set camera.Slot.AttachedCompositor = null (detach) before re-attaching elsewhere","Use a separate CameraComponent per slot instead of reusing one instance","Ensure attach logic runs only once (guard with a bool or only on entity add)"],"exampleFix":"// before\ncameraProcessor.AttachCameraToSlot(compositor, camera);\n// after\nif (camera.Slot.AttachedCompositor == null)\n    cameraProcessor.AttachCameraToSlot(compositor, camera);","handlingStrategy":"type-guard","validationCode":"if (camera.Slot?.AttachedCompositor != null) return; // already attached","typeGuard":"bool AlreadyAttached(CameraComponent c) => c?.Slot?.AttachedCompositor != null;","tryCatchPattern":"try { AttachCameraToSlot(compositor, camera); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"already attached\")) { /* no-op */ }","preventionTips":["Run attach logic only once per camera (entity-add time, not every frame)","Use one CameraComponent per slot","Detach before re-attaching elsewhere","Never share camera components across scene setups"],"tags":["graphics","camera","stride"],"backgroundTag":"invalid-state-transition","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}