stride3d/stride · error · InvalidOperationException

This GamePad's index can not be changed

Error message

This GamePad's index can not be changed

What it means

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.

Solutions

  1. Check CanChangeIndex before assigning Index
  2. Map players via your own device-to-player dictionary instead of mutating Index
  3. Listen for device connection events and assign players by device identity, not index mutation

Example fix

// before
gamePad.Index = playerNumber;
// after
if (gamePad.CanChangeIndex)
    gamePad.Index = playerNumber;
else
    playerMap[playerNumber] = gamePad; // map externally
Defensive patterns

Strategy: validation

Validate before calling

if (gamePad.CanChangeIndex)
    gamePad.Index = desiredIndex;
else
    playerMap[desiredIndex] = gamePad;

Type guard

bool IndexAssignable(GamePadDeviceBase p) => p.CanChangeIndex;

Try / catch

try { gamePad.Index = value; }
catch (InvalidOperationException) { playerMap[value] = gamePad; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/3717b79c1c2e9dc1. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Input/GamePadDeviceBase.cs:30

        private readonly HashSet<GamePadButton> releasedButtons = new HashSet<GamePadButton>();
        private readonly HashSet<GamePadButton> pressedButtons = new HashSet<GamePadButton>();
        private readonly HashSet<GamePadButton> downButtons = new HashSet<GamePadButton>();
        private int index;

        public abstract string Name { get; }
        public abstract Guid Id { get; }
        public abstract Guid ProductId { get; }
        public abstract GamePadState State { get; }
        public bool CanChangeIndex { get; protected set; } = true;
        public int Priority { get; set; }

        public int Index
        {
            get { return index; }
            set
            {
                if (!CanChangeIndex)
                    throw new InvalidOperationException("This GamePad's index can not be changed");
                SetIndexInternal(value, false);
            }
        }

        public Core.Collections.IReadOnlySet<GamePadButton> PressedButtons { get; }
        public Core.Collections.IReadOnlySet<GamePadButton> ReleasedButtons { get; }
        public Core.Collections.IReadOnlySet<GamePadButton> DownButtons { get; }

        public abstract IInputSource Source { get; }

        public event EventHandler<GamePadIndexChangedEventArgs> IndexChanged;

        public abstract void Update(List<InputEvent> inputEvents);
        public abstract void SetVibration(float smallLeft, float smallRight, float largeLeft, float largeRight);

        protected GamePadDeviceBase()
        {
            PressedButtons = new ReadOnlySet<GamePadButton>(pressedButtons);

View on GitHub (pinned to 96fad776d2)