Quick answer: Pygame Joystick missing after unplug-and-replug? Listen for JOYDEVICEADDED / JOYDEVICEREMOVED events — pygame doesn’t re-enumerate automatically.

A controller unplugged mid-game stays unresponsive after replug. Pygame keeps the dead Joystick object cached.

JOYDEVICEADDED Handler

if event.type == pygame.JOYDEVICEADDED:
    joy = pygame.joystick.Joystick(event.device_index)
    joy.init()

The new device index from the event is what you instantiate. Existing Joystick objects are still tied to the old index, which is invalid.

Remove on Disconnect

On JOYDEVICEREMOVED, drop the Joystick from your active list. Reading axes / buttons from a disconnected joystick raises or returns zeros depending on platform.

Instance ID vs Index

The device index changes across re-enumeration; the instance ID stays stable per physical device for the session. Track by instance ID to recognize the same controller across plugs.

Verifying

Unplug then replug the controller. Inputs resume without restarting the game.

“Replug requires new Joystick objects. Listen for device events.”

Treat “input” as a service that emits abstract events — the joystick plumbing changes per platform, your gameplay code shouldn’t.