docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class AndroidGamepad

    Represents a gamepad device on Android, providing unified support for various controller types.

    Inheritance
    object
    InputControl
    InputDevice
    Gamepad
    AndroidGamepad
    AndroidGamepadWithDpadAxes
    AndroidGamepadWithDpadButtons
    Implements
    IDualMotorRumble
    IHaptics
    Inherited Members
    Gamepad.buttonWest
    Gamepad.buttonNorth
    Gamepad.buttonSouth
    Gamepad.buttonEast
    Gamepad.leftStickButton
    Gamepad.rightStickButton
    Gamepad.startButton
    Gamepad.selectButton
    Gamepad.dpad
    Gamepad.leftShoulder
    Gamepad.rightShoulder
    Gamepad.leftStick
    Gamepad.rightStick
    Gamepad.leftTrigger
    Gamepad.rightTrigger
    Gamepad.aButton
    Gamepad.bButton
    Gamepad.xButton
    Gamepad.yButton
    Gamepad.triangleButton
    Gamepad.squareButton
    Gamepad.circleButton
    Gamepad.crossButton
    Gamepad.this[GamepadButton]
    Gamepad.current
    Gamepad.all
    Gamepad.FinishSetup()
    Gamepad.MakeCurrent()
    Gamepad.OnAdded()
    Gamepad.OnRemoved()
    Gamepad.PauseHaptics()
    Gamepad.ResumeHaptics()
    Gamepad.ResetHaptics()
    Gamepad.SetMotorSpeeds(float, float)
    InputDevice.InvalidDeviceId
    InputDevice.description
    InputDevice.enabled
    InputDevice.canRunInBackground
    InputDevice.added
    InputDevice.remote
    InputDevice.native
    InputDevice.updateBeforeRender
    InputDevice.deviceId
    InputDevice.lastUpdateTime
    InputDevice.wasUpdatedThisFrame
    InputDevice.allControls
    InputDevice.valueType
    InputDevice.valueSizeInBytes
    InputDevice.ReadValueFromBufferAsObject(void*, int)
    InputDevice.ReadValueFromStateAsObject(void*)
    InputDevice.ReadValueFromStateIntoBuffer(void*, void*, int)
    InputDevice.CompareValue(void*, void*)
    InputDevice.OnConfigurationChanged()
    InputDevice.ExecuteCommand<TCommand>(ref TCommand)
    InputDevice.ExecuteCommand(InputDeviceCommand*)
    InputControl.name
    InputControl.displayName
    InputControl.shortDisplayName
    InputControl.path
    InputControl.layout
    InputControl.variants
    InputControl.device
    InputControl.parent
    InputControl.children
    InputControl.usages
    InputControl.aliases
    InputControl.stateBlock
    InputControl.noisy
    InputControl.synthetic
    InputControl.this[string]
    InputControl.magnitude
    InputControl.ToString()
    InputControl.EvaluateMagnitude()
    InputControl.EvaluateMagnitude(void*)
    InputControl.WriteValueFromBufferIntoState(void*, int, void*)
    InputControl.WriteValueFromObjectIntoState(object, void*)
    InputControl.TryGetChildControl(string)
    InputControl.TryGetChildControl<TControl>(string)
    InputControl.GetChildControl(string)
    InputControl.GetChildControl<TControl>(string)
    InputControl.RefreshConfigurationIfNeeded()
    InputControl.RefreshConfiguration()
    InputControl.m_StateBlock
    InputControl.currentStatePtr
    InputControl.previousFrameStatePtr
    InputControl.defaultStatePtr
    InputControl.noiseMaskPtr
    InputControl.stateOffsetRelativeToDeviceRoot
    InputControl.optimizedControlDataType
    InputControl.CalculateOptimizedControlDataType()
    InputControl.ApplyParameterChanges()
    Namespace: UnityEngine.InputSystem.Android
    Assembly: Unity.InputSystem.dll
    Syntax
    public class AndroidGamepad : Gamepad, IDualMotorRumble, IHaptics
    Remarks

    This layout covers multiple Android-supported gamepads, including but not limited to:

    • ELAN PLAYSTATION(R)3 Controller
    • My-Power CO., LTD. PS(R) Controller Adaptor
    • Sony Interactive Entertainment Wireless (PS4 DualShock)
    • Xbox Wireless Controller (Xbox One)
    • NVIDIA Controller v01.03/v01.04
    • (More may be added later)

    Typical Android Axis and Key Mappings

    Control Mapping
    Left Stick AXIS_X(0) / AXIS_Y(1)
    Right Stick AXIS_Z(11) / AXIS_RZ(14)
    L1 KEYCODE_BUTTON_L1(102)
    R1 KEYCODE_BUTTON_R1(103)
    L2 AXIS_BRAKE(23)
    R2 AXIS_GAS(22)
    Left Thumb KEYCODE_BUTTON_THUMBL(106)
    Right Thumb KEYCODE_BUTTON_THUMBR(107)
    X KEYCODE_BUTTON_X(99)
    Y KEYCODE_BUTTON_Y(100)
    B KEYCODE_BUTTON_B(97)
    A KEYCODE_BUTTON_A(96)
    DPAD AXIS_HAT_X(15), AXIS_HAT_Y(16) or KEYCODE_DPAD_*

    Notes

    • NVIDIA Shield Console

      • The L2 and R2 triggers generate both AXIS_BRAKE / AXIS_GAS and AXIS_LTRIGGER / AXIS_RTRIGGER events.
      • On most Android phones, only AXIS_BRAKE and AXIS_GAS are reported; AXIS_LTRIGGER and AXIS_RTRIGGER are not invoked.
      • For consistency across devices, triggers are mapped exclusively to AXIS_BRAKE and AXIS_GAS.
      • The Shield also reports KEYCODE_BACK instead of KEYCODE_BUTTON_SELECT, causing the Options (Xbox), View (DualShock), or Select buttons to be non-functional.
    • PS4 Controller Compatibility

      • Official PS4 controller support is available starting from Android 10 and later (see: https://playstation.com/en-us/support/hardware/ps4-pair-dualshock-4-wireless-with-sony-xperia-and-android).
      • On older Android versions, driver implementations vary by manufacturer. Some vendors have partially fixed DualShock support in custom drivers, leading to inconsistent mappings.
    • Driver-Dependent Behavior

      • Gamepad mappings may differ even between devices running the same Android version.
        • For example, on Android 8.0:
          • NVIDIA Shield Console: buttons map correctly according to AndroidGameControllerState (for example, L1 → ButtonL1, R1 → ButtonR1).
          • Samsung Galaxy S9 / S8 and Xiaomi Mi Note2: mappings are inconsistent (for example, L1 → ButtonY, R1 → ButtonZ).
      • These discrepancies stem from device-specific driver differences, not the Android OS itself.

    Because mapping inconsistencies depend on vendor-specific drivers, it’s impractical to maintain per-device remaps.

    Implements

    IDualMotorRumble
    IHaptics

    Extension Methods

    InputControlExtensions.CheckStateIsAtDefault(InputControl)
    InputControlExtensions.CheckStateIsAtDefault(InputControl, void*, void*)
    InputControlExtensions.CheckStateIsAtDefaultIgnoringNoise(InputControl)
    InputControlExtensions.CheckStateIsAtDefaultIgnoringNoise(InputControl, void*)
    InputControlExtensions.CompareState(InputControl, void*, void*)
    InputControlExtensions.CompareState(InputControl, void*, void*, void*)
    InputControlExtensions.CompareStateIgnoringNoise(InputControl, void*)
    InputControlExtensions.FindControlsRecursive<TControl>(InputControl, IList<TControl>, Func<TControl, bool>)
    InputControlExtensions.FindInParentChain<TControl>(InputControl)
    InputControlExtensions.GetStatePtrFromStateEvent(InputControl, InputEventPtr)
    InputControlExtensions.HasValueChangeInEvent(InputControl, InputEventPtr)
    InputControlExtensions.HasValueChangeInState(InputControl, void*)
    InputControlExtensions.IsActuated(InputControl, float)
    InputControlExtensions.IsPressed(InputControl, float)
    InputControlExtensions.ReadDefaultValueAsObject(InputControl)
    InputControlExtensions.ReadValueAsObject(InputControl)
    InputControlExtensions.ReadValueFromEventAsObject(InputControl, InputEventPtr)
    InputControlExtensions.ReadValueIntoBuffer(InputControl, void*, int)
    InputControlExtensions.ResetToDefaultStateInEvent(InputControl, InputEventPtr)
    InputControlExtensions.WriteValueFromObjectIntoEvent(InputControl, InputEventPtr, object)
    InputControlExtensions.WriteValueIntoEvent<TValue>(InputControl, TValue, InputEventPtr)
    InputControlExtensions.WriteValueIntoState(InputControl, void*)
    InputControlExtensions.WriteValueIntoState<TValue>(InputControl, TValue, void*)
    InputControlExtensions.CopyState(InputDevice, void*, int)
    InputControlExtensions.CopyState<TState>(InputDevice, out TState)
    In This Article
    Back to top
    Copyright © 2025 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)