{"record":{"id":"3717b79c1c2e9dc1","repo":"stride3d/stride","slug":"this-gamepad-s-index-can-not-be-changed","errorCode":null,"errorMessage":"This GamePad's index can not be changed","messagePattern":"This GamePad's index can not be changed","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Input/GamePadDeviceBase.cs","lineNumber":30,"sourceCode":"        private readonly HashSet<GamePadButton> releasedButtons = new HashSet<GamePadButton>();\n        private readonly HashSet<GamePadButton> pressedButtons = new HashSet<GamePadButton>();\n        private readonly HashSet<GamePadButton> downButtons = new HashSet<GamePadButton>();\n        private int index;\n\n        public abstract string Name { get; }\n        public abstract Guid Id { get; }\n        public abstract Guid ProductId { get; }\n        public abstract GamePadState State { get; }\n        public bool CanChangeIndex { get; protected set; } = true;\n        public int Priority { get; set; }\n\n        public int Index\n        {\n            get { return index; }\n            set\n            {\n                if (!CanChangeIndex)\n                    throw new InvalidOperationException(\"This GamePad's index can not be changed\");\n                SetIndexInternal(value, false);\n            }\n        }\n\n        public Core.Collections.IReadOnlySet<GamePadButton> PressedButtons { get; }\n        public Core.Collections.IReadOnlySet<GamePadButton> ReleasedButtons { get; }\n        public Core.Collections.IReadOnlySet<GamePadButton> DownButtons { get; }\n\n        public abstract IInputSource Source { get; }\n\n        public event EventHandler<GamePadIndexChangedEventArgs> IndexChanged;\n\n        public abstract void Update(List<InputEvent> inputEvents);\n        public abstract void SetVibration(float smallLeft, float smallRight, float largeLeft, float largeRight);\n\n        protected GamePadDeviceBase()\n        {\n            PressedButtons = new ReadOnlySet<GamePadButton>(pressedButtons);","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Input/GamePadDeviceBase.cs#L12-L48","documentation":"GamePadDeviceBase.Index setter only allows reassignment when the device reports CanChangeIndex. Gamepads with fixed hardware assignment throw InvalidOperationException 'This GamePad's index can not be changed' when code tries to set Index anyway.","triggerScenarios":"Setting the Index property on a GamePadDeviceBase instance whose CanChangeIndex is false — typical for concrete gamepad implementations where the index is dictated by the driver/hardware.","commonSituations":"Trying to reorder gamepads by assigning Index in code; porting code that assumed all devices support index reassignment; a user script mapping player numbers by setting device Index.","solutions":["Check CanChangeIndex before assigning Index","Map players via your own device-to-player dictionary instead of mutating Index","Listen for device connection events and assign players by device identity, not index mutation"],"exampleFix":"// before\ngamePad.Index = playerNumber;\n// after\nif (gamePad.CanChangeIndex)\n    gamePad.Index = playerNumber;\nelse\n    playerMap[playerNumber] = gamePad; // map externally","handlingStrategy":"validation","validationCode":"if (gamePad.CanChangeIndex)\n    gamePad.Index = desiredIndex;\nelse\n    playerMap[desiredIndex] = gamePad;","typeGuard":"bool IndexAssignable(GamePadDeviceBase p) => p.CanChangeIndex;","tryCatchPattern":"try { gamePad.Index = value; }\ncatch (InvalidOperationException) { playerMap[value] = gamePad; }","preventionTips":["Never assume Index is mutable; design player assignment around device identity","Check CanChangeIndex once at device connect time","Keep an external device-to-player mapping"],"tags":["input","gamepad","device"],"backgroundTag":"unsupported-operation","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"}