docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Query and control gamepads in code

    You can use the methods in the Gamepad class to access information about the gamepads connected to your application.

    Discover all connected devices

    There are various ways to discover the currently connected devices. To query a list of all connected devices (doesn't allocate; read-only access) use the following:

    Warning

    It looks like the sample you are looking for does not exist.

    To get notified when a device is added or removed:

    Warning

    It looks like the sample you are looking for does not exist.

    To find all gamepads and joysticks:

    Warning

    It looks like the sample you are looking for does not exist.

    Access gamepad buttons

    To access gamepad buttons, you can use the indexer property on Gamepad and the GamepadButton enumeration:

    Warning

    It looks like the sample you are looking for does not exist.

    Gamepads have both Xbox-style and PlayStation-style aliases on buttons. For example, the following four accessors all retrieve the same north face button:

    Warning

    It looks like the sample you are looking for does not exist.

    Add a deadzone to a gamepad

    Deadzones prevent accidental input due to slight variations in where gamepad sticks come to rest at their center point. They allow a certain small inner area where the input is considered to be zero even if the input is slightly off from the zero position.

    To add a deadzone to gamepad stick, put a stick deadzone Processor on the sticks, like this:

    Warning

    It looks like the sample you are looking for does not exist.

    You can do the same in your C# state structs:

    Warning

    It looks like the sample you are looking for does not exist.

    The gamepad layout already adds stick deadzone processors which take their minimum and maximum values from InputSettings.defaultDeadzoneMin and InputSettings.defaultDeadzoneMax.

    Using gamepads for mouse input

    To use a gamepad for driving mouse input, refer to the sample called Gamepad Mouse Cursor. To access the sample, open the Package Manager window, and select the Input System package. Then select the Samples tab. The sample demonstrates how to set up gamepad input to drive a virtual mouse cursor.

    You can also use the VirtualMouseInput component to control the hardware or software cursor. For more information, refer to VirtualMouseInput component.

    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)