docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class Gamepad

    An Xbox-style gamepad with two sticks, a D-Pad, four face buttons, two triggers, two shoulder buttons, and two menu buttons that usually sit in the midsection of the gamepad.

    Inheritance
    object
    InputControl
    InputDevice
    Gamepad
    AndroidGamepad
    DualShockGamepad
    NimbusGamepadHid
    SwitchProControllerHID
    WebGLGamepad
    XInputController
    iOSGameController
    Implements
    IDualMotorRumble
    IHaptics
    Inherited Members
    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
    Assembly: Unity.InputSystem.dll
    Syntax
    public class Gamepad : InputDevice, IDualMotorRumble, IHaptics
    Remarks

    The Gamepad layout provides a standardized layouts for gamepads. Generally, if a specific device is represented as a Gamepad, the controls, such as the face buttons, are guaranteed to be mapped correctly and consistently. If, based on the set of supported devices available to the input system, this cannot be guaranteed, a given device is usually represented as a generic Joystick or as just a plain HID instead.

    Examples
    using UnityEngine;
    using UnityEngine.InputSystem;
    
    namespace DocCodeSamples.Tests
    {
        internal class GamepadExample : MonoBehaviour
        {
            void Start()
            {
                // Print all connected gamepads
                Debug.Log(string.Join("\n", Gamepad.all));
            }
    
            void Update()
            {
                var gamepad = Gamepad.current;
    
                // No gamepad connected.
                if (gamepad == null)
                {
                    return;
                }
    
                // Check if "Button North" was pressed this frame
                if (gamepad.buttonNorth.wasPressedThisFrame)
                {
                    Debug.Log("Button North was pressed");
                }
    
                // Check if the button control is being continuously actuated and read its value
                if (gamepad.rightTrigger.IsActuated())
                {
                    Debug.Log("Right trigger value: " + gamepad.rightTrigger.ReadValue());
                }
    
                // Read left stick value and perform some code based on the value
                Vector2 move = gamepad.leftStick.ReadValue();
                {
                    // Use the Vector2 move for the game logic here
                }
    
                // Creating haptic feedback while "Button South" is pressed and stopping it when released.
                if (gamepad.buttonSouth.wasPressedThisFrame)
                {
                    gamepad.SetMotorSpeeds(0.2f, 1.0f);
                }
                else if (gamepad.buttonSouth.wasReleasedThisFrame)
                {
                    gamepad.ResetHaptics();
                }
            }
        }
    }

    Properties

    this[GamepadButton]

    Retrieve a gamepad button by its GamepadButton enumeration constant.

    Declaration
    public ButtonControl this[GamepadButton button] { get; }
    Parameters
    Type Name Description
    GamepadButton button

    Button to retrieve.

    Property Value
    Type Description
    ButtonControl
    Exceptions
    Type Condition
    ArgumentException

    button is not a valid gamepad button value.

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    aButton

    Same as buttonSouth. Xbox-style alias.

    Declaration
    public ButtonControl aButton { get; }
    Property Value
    Type Description
    ButtonControl
    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    all

    A list of gamepads currently connected to the system.

    Declaration
    public static ReadOnlyArray<Gamepad> all { get; }
    Property Value
    Type Description
    ReadOnlyArray<Gamepad>
    Remarks

    Returns all currently connected gamepads.

    Does not cause GC allocation.

    Do not hold on to the value returned by this getter but rather query it whenever you need it. Whenever the gamepad setup changes, the value returned by this getter is invalidated.

    Alternately, for querying a single gamepad, you can use current for example.

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    bButton

    Same as buttonEast. Xbox-style alias.

    Declaration
    public ButtonControl bButton { get; }
    Property Value
    Type Description
    ButtonControl
    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    buttonEast

    The right face button of the gamepad.

    Declaration
    public ButtonControl buttonEast { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    Remarks

    Control representing the B/Circle face button. On an Xbox controller, this is the bButton and on the PS4 controller, this is the circleButton.

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    buttonNorth

    The top face button of the gamepad.

    Declaration
    public ButtonControl buttonNorth { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    Remarks

    Control representing the Y/Triangle face button. On an Xbox controller, this is the yButton and on the PS4 controller, this is the triangleButton.

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    buttonSouth

    The bottom face button of the gamepad.

    Declaration
    public ButtonControl buttonSouth { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    Remarks

    Control representing the A/Cross face button. On an Xbox controller, this is the aButton and on the PS4 controller, this is the crossButton.

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    buttonWest

    The left face button of the gamepad.

    Declaration
    public ButtonControl buttonWest { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    Remarks

    Control representing the X/Square face button. On an Xbox controller, this is the xButton and on the PS4 controller, this is the squareButton.

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    circleButton

    Same as buttonEast. PS4-style alias.

    Declaration
    public ButtonControl circleButton { get; }
    Property Value
    Type Description
    ButtonControl
    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    crossButton

    Same as buttonSouth. PS4-style alias.

    Declaration
    public ButtonControl crossButton { get; }
    Property Value
    Type Description
    ButtonControl
    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    current

    The gamepad last used/connected by the player or null if there is no gamepad connected to the system.

    Declaration
    public static Gamepad current { get; }
    Property Value
    Type Description
    Gamepad
    Remarks

    When added, a device is automatically made current (see MakeCurrent()), so when connecting a gamepad, it will also become current. After that, it will only become current again when input change on non-noisy controls (see noisy) is received. It will also be available once all is queried.

    For local multiplayer scenarios (or whenever there are multiple gamepads that need to be usable in a concurrent fashion), it is not recommended to rely on this property. Instead, it is recommended to use PlayerInput or InputUser.

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    dpad

    The 4-way directional pad on the gamepad.

    Declaration
    public DpadControl dpad { get; protected set; }
    Property Value
    Type Description
    DpadControl
    Remarks

    Control representing the d-pad.

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    leftShoulder

    The left shoulder/bumper button that sits on top of leftTrigger.

    Declaration
    public ButtonControl leftShoulder { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    Remarks

    Control representing the left shoulder button. On Xbox controllers, this is usually called "left bumper" whereas on PS4 controllers, this button is referred to as "L1".

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    leftStick

    The left thumbstick on the gamepad.

    Declaration
    public StickControl leftStick { get; protected set; }
    Property Value
    Type Description
    StickControl
    Remarks

    Control representing the left thumbstick.

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    leftStickButton

    The button that gets triggered when leftStick is pressed down.

    Declaration
    public ButtonControl leftStickButton { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    Remarks

    Control representing a click with the left stick.

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    leftTrigger

    The left trigger button sitting below leftShoulder.

    Declaration
    public ButtonControl leftTrigger { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    Remarks

    Control representing the left trigger button. On PS4 controllers, this button is referred to as "L2".

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    rightShoulder

    The right shoulder/bumper button that sits on top of rightTrigger.

    Declaration
    public ButtonControl rightShoulder { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    Remarks

    Control representing the right shoulder button. On Xbox controllers, this is usually called "right bumper" whereas on PS4 controllers, this button is referred to as "R1".

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    rightStick

    The right thumbstick on the gamepad.

    Declaration
    public StickControl rightStick { get; protected set; }
    Property Value
    Type Description
    StickControl
    Remarks

    Control representing the right thumbstick.

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    rightStickButton

    The button that gets triggered when rightStick is pressed down.

    Declaration
    public ButtonControl rightStickButton { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    Remarks

    Control representing a click with the right stick.

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    rightTrigger

    The right trigger button sitting below rightShoulder.

    Declaration
    public ButtonControl rightTrigger { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    Remarks

    Control representing the right trigger button. On PS4 controllers, this button is referred to as "R2".

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    selectButton

    The left button in the middle section of the gamepad (called "view" on Xbox controllers and "share" on PS4 controllers).

    Declaration
    public ButtonControl selectButton { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    Remarks

    Control representing the left button in midsection.

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    squareButton

    Same as buttonWest. PS4-style alias.

    Declaration
    public ButtonControl squareButton { get; }
    Property Value
    Type Description
    ButtonControl
    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    startButton

    The right button in the middle section of the gamepad (called "menu" on Xbox controllers and "options" on PS4 controllers).

    Declaration
    public ButtonControl startButton { get; protected set; }
    Property Value
    Type Description
    ButtonControl
    Remarks

    Control representing the right button in midsection.

    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    triangleButton

    Same as buttonNorth. PS4-style alias.

    Declaration
    public ButtonControl triangleButton { get; }
    Property Value
    Type Description
    ButtonControl
    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    xButton

    Same as buttonWest Xbox-style alias.

    Declaration
    public ButtonControl xButton { get; }
    Property Value
    Type Description
    ButtonControl
    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    yButton

    Same as buttonNorth. Xbox-style alias.

    Declaration
    public ButtonControl yButton { get; }
    Property Value
    Type Description
    ButtonControl
    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    Methods

    FinishSetup()

    Perform final initialization tasks after the control hierarchy has been put into place.

    Declaration
    protected override void FinishSetup()
    Overrides
    InputControl.FinishSetup()
    Remarks

    This method can be overridden to perform control- or device-specific setup work. The most common use case is for looking up child controls and storing them in local getters.

    Examples
      public class MyDevice : InputDevice
                            {
                                public ButtonControl button { get; private set; }
                                public AxisControl axis { get; private set; }
    
                                protected override void OnFinishSetup()
                                {
                                    // Cache controls in getters.
                                    button = GetChildControl("button");
                                    axis = GetChildControl("axis");
                                }
                            }
    
    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    MakeCurrent()

    Make the gamepad the current gamepad.

    Declaration
    public override void MakeCurrent()
    Overrides
    InputDevice.MakeCurrent()
    Remarks

    This is called automatically by the system when there is input on a gamepad.

    More remarks are available in MakeCurrent() when it comes to devices with noisy controls.

    Examples
    using System;
    using UnityEngine;
    using UnityEngine.InputSystem;
    
    public class MakeCurrentGamepadExample : MonoBehaviour
    {
        void Update()
        {
            /// Make the first Gamepad always the current one
            if (Gamepad.all.Count > 0)
            {
                Gamepad.all[0].MakeCurrent();
            }
        }
    }
    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    OnAdded()

    Called by the system when the device is added to devices.

    Declaration
    protected override void OnAdded()
    Overrides
    InputDevice.OnAdded()
    Remarks

    This is called after the device has already been added. devicesAddedOnRemoved()

    Examples
      using UnityEngine.InputSystem;
    
                                                                                                                                                                                                                                  public class MyDevice : InputDevice
                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                      public static MyDevice current { get; private set; }
                                                                                                                                                                                                                                      protected override void OnAdded()
                                                                                                                                                                                                                                      {
                                                                                                                                                                                                                                          // use this context to assign the current device for instance
                                                                                                                                                                                                                                          base.OnAdded();
                                                                                                                                                                                                                                          current = this;
                                                                                                                                                                                                                                      }
                                                                                                                                                                                                                                  }
    
    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    OnRemoved()

    Called by the system when the device is removed from devices.

    Declaration
    protected override void OnRemoved()
    Overrides
    InputDevice.OnRemoved()
    Remarks

    This is called after the device has already been removed. devicesRemovedOnAdded()

    Examples
      using UnityEngine.InputSystem;
    
                                                                                                                                                                                                                                  public class MyDevice : InputDevice
                                                                                                                                                                                                                                  {
                                                                                                                                                                                                                                      public static MyDevice current { get; private set; }
                                                                                                                                                                                                                                      protected override void OnRemoved()
                                                                                                                                                                                                                                      {
                                                                                                                                                                                                                                          // use this context to unassign the current device for instance
                                                                                                                                                                                                                                          base.OnRemoved();
                                                                                                                                                                                                                                          if (current == this)
                                                                                                                                                                                                                                              current = null;
                                                                                                                                                                                                                                      }
                                                                                                                                                                                                                                  }
    
    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    PauseHaptics()

    Pause rumble effects on the gamepad.

    Declaration
    public virtual void PauseHaptics()
    Remarks

    It will pause rumble effects and save the current motor speeds. Resume from those speeds with ResumeHaptics(). Some devices such as DualSenseGamepadHID and DualShock4GamepadHID can also set the LED color when this method is called.

    Examples
    using UnityEngine;
    using UnityEngine.InputSystem;
    
    namespace DocCodeSamples.Tests
    {
        internal class GamepadHapticsExample : MonoBehaviour
        {
            bool hapticsArePaused = false;
    
            void Update()
            {
                var gamepad = Gamepad.current;
    
                // No gamepad connected, no need to continue.
                if (gamepad == null)
                    return;
    
                float leftTrigger = gamepad.leftTrigger.ReadValue();
                float rightTrigger = gamepad.rightTrigger.ReadValue();
    
                // Only set motor speeds if haptics were not paused and if trigger is actuated.
                // Both triggers must be actuated past 0.2f to start haptics.
                if (!hapticsArePaused &&
                    (gamepad.leftTrigger.IsActuated() || gamepad.rightTrigger.IsActuated()))
                    gamepad.SetMotorSpeeds(
                        leftTrigger < 0.2f ? 0.0f : leftTrigger,
                        rightTrigger < 0.2f ? 0.0f : rightTrigger);
    
                // Toggle haptics "playback" when "Button South" is pressed.
                // Notice that if you release the triggers after pausing,
                // and press the button again, haptics will resume.
                if (gamepad.buttonSouth.wasPressedThisFrame)
                {
                    if (hapticsArePaused)
                        gamepad.ResumeHaptics();
                    else
                        gamepad.PauseHaptics();
    
                    hapticsArePaused = !hapticsArePaused;
                }
    
                // Notice that if you release the triggers after pausing,
                // and press the Start button, haptics will be reset.
                if (gamepad.startButton.wasPressedThisFrame)
                    gamepad.ResetHaptics();
            }
        }
    }
    See Also
    IDualMotorRumble

    ResetHaptics()

    Resets rumble effects on the gamepad by setting motor speeds to 0.

    Declaration
    public virtual void ResetHaptics()
    Remarks

    Some devices such as DualSenseGamepadHID and DualShock4GamepadHID can also set the LED color when this method is called.

    Examples
    using UnityEngine;
    using UnityEngine.InputSystem;
    
    namespace DocCodeSamples.Tests
    {
        internal class GamepadHapticsExample : MonoBehaviour
        {
            bool hapticsArePaused = false;
    
            void Update()
            {
                var gamepad = Gamepad.current;
    
                // No gamepad connected, no need to continue.
                if (gamepad == null)
                    return;
    
                float leftTrigger = gamepad.leftTrigger.ReadValue();
                float rightTrigger = gamepad.rightTrigger.ReadValue();
    
                // Only set motor speeds if haptics were not paused and if trigger is actuated.
                // Both triggers must be actuated past 0.2f to start haptics.
                if (!hapticsArePaused &&
                    (gamepad.leftTrigger.IsActuated() || gamepad.rightTrigger.IsActuated()))
                    gamepad.SetMotorSpeeds(
                        leftTrigger < 0.2f ? 0.0f : leftTrigger,
                        rightTrigger < 0.2f ? 0.0f : rightTrigger);
    
                // Toggle haptics "playback" when "Button South" is pressed.
                // Notice that if you release the triggers after pausing,
                // and press the button again, haptics will resume.
                if (gamepad.buttonSouth.wasPressedThisFrame)
                {
                    if (hapticsArePaused)
                        gamepad.ResumeHaptics();
                    else
                        gamepad.PauseHaptics();
    
                    hapticsArePaused = !hapticsArePaused;
                }
    
                // Notice that if you release the triggers after pausing,
                // and press the Start button, haptics will be reset.
                if (gamepad.startButton.wasPressedThisFrame)
                    gamepad.ResetHaptics();
            }
        }
    }
    See Also
    IDualMotorRumble

    ResumeHaptics()

    Resume rumble effects on the gamepad.

    Declaration
    public virtual void ResumeHaptics()
    Remarks

    It will resume rumble effects from the previously set motor speeds, such as motor speeds saved when calling PauseHaptics(). Some devices such as DualSenseGamepadHID and DualShock4GamepadHID can also set the LED color when this method is called.

    Examples
    using UnityEngine;
    using UnityEngine.InputSystem;
    
    namespace DocCodeSamples.Tests
    {
        internal class GamepadHapticsExample : MonoBehaviour
        {
            bool hapticsArePaused = false;
    
            void Update()
            {
                var gamepad = Gamepad.current;
    
                // No gamepad connected, no need to continue.
                if (gamepad == null)
                    return;
    
                float leftTrigger = gamepad.leftTrigger.ReadValue();
                float rightTrigger = gamepad.rightTrigger.ReadValue();
    
                // Only set motor speeds if haptics were not paused and if trigger is actuated.
                // Both triggers must be actuated past 0.2f to start haptics.
                if (!hapticsArePaused &&
                    (gamepad.leftTrigger.IsActuated() || gamepad.rightTrigger.IsActuated()))
                    gamepad.SetMotorSpeeds(
                        leftTrigger < 0.2f ? 0.0f : leftTrigger,
                        rightTrigger < 0.2f ? 0.0f : rightTrigger);
    
                // Toggle haptics "playback" when "Button South" is pressed.
                // Notice that if you release the triggers after pausing,
                // and press the button again, haptics will resume.
                if (gamepad.buttonSouth.wasPressedThisFrame)
                {
                    if (hapticsArePaused)
                        gamepad.ResumeHaptics();
                    else
                        gamepad.PauseHaptics();
    
                    hapticsArePaused = !hapticsArePaused;
                }
    
                // Notice that if you release the triggers after pausing,
                // and press the Start button, haptics will be reset.
                if (gamepad.startButton.wasPressedThisFrame)
                    gamepad.ResetHaptics();
            }
        }
    }
    See Also
    IDualMotorRumble

    SetMotorSpeeds(float, float)

    Set the motor speeds of the low-frequency (usually on the left) and high-frequency (usually on the right) motors.

    Declaration
    public virtual void SetMotorSpeeds(float lowFrequency, float highFrequency)
    Parameters
    Type Name Description
    float lowFrequency

    Speed of the low-frequency (left) motor. Normalized [0..1] value with 1 indicating maximum speed and 0 indicating the motor is turned off. Will automatically be clamped into range.

    float highFrequency

    Speed of the high-frequency (right) motor. Normalized [0..1] value with 1 indicating maximum speed and 0 indicating the motor is turned off. Will automatically be clamped into range.

    Remarks

    Note that hardware will put limits on the level of control you have over the motors. Rumbling the motors at maximum speed for an extended period of time may cause them to turn off for some time to prevent overheating. Also, how quickly the motors react and how often the speed can be updated will depend on the hardware and drivers.

    Examples
    using UnityEngine;
    using UnityEngine.InputSystem;
    
    namespace DocCodeSamples.Tests
    {
        internal class GamepadHapticsExample : MonoBehaviour
        {
            bool hapticsArePaused = false;
    
            void Update()
            {
                var gamepad = Gamepad.current;
    
                // No gamepad connected, no need to continue.
                if (gamepad == null)
                    return;
    
                float leftTrigger = gamepad.leftTrigger.ReadValue();
                float rightTrigger = gamepad.rightTrigger.ReadValue();
    
                // Only set motor speeds if haptics were not paused and if trigger is actuated.
                // Both triggers must be actuated past 0.2f to start haptics.
                if (!hapticsArePaused &&
                    (gamepad.leftTrigger.IsActuated() || gamepad.rightTrigger.IsActuated()))
                    gamepad.SetMotorSpeeds(
                        leftTrigger < 0.2f ? 0.0f : leftTrigger,
                        rightTrigger < 0.2f ? 0.0f : rightTrigger);
    
                // Toggle haptics "playback" when "Button South" is pressed.
                // Notice that if you release the triggers after pausing,
                // and press the button again, haptics will resume.
                if (gamepad.buttonSouth.wasPressedThisFrame)
                {
                    if (hapticsArePaused)
                        gamepad.ResumeHaptics();
                    else
                        gamepad.PauseHaptics();
    
                    hapticsArePaused = !hapticsArePaused;
                }
    
                // Notice that if you release the triggers after pausing,
                // and press the Start button, haptics will be reset.
                if (gamepad.startButton.wasPressedThisFrame)
                    gamepad.ResetHaptics();
            }
        }
    }
    See Also
    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    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)

    See Also

    all
    current
    GamepadState
    InputDevice
    SetMotorSpeeds(float, float)
    wasPressedThisFrame

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Properties
      • this[GamepadButton]
      • aButton
      • all
      • bButton
      • buttonEast
      • buttonNorth
      • buttonSouth
      • buttonWest
      • circleButton
      • crossButton
      • current
      • dpad
      • leftShoulder
      • leftStick
      • leftStickButton
      • leftTrigger
      • rightShoulder
      • rightStick
      • rightStickButton
      • rightTrigger
      • selectButton
      • squareButton
      • startButton
      • triangleButton
      • xButton
      • yButton
    • Methods
      • FinishSetup()
      • MakeCurrent()
      • OnAdded()
      • OnRemoved()
      • PauseHaptics()
      • ResetHaptics()
      • ResumeHaptics()
      • SetMotorSpeeds(float, float)
    • Implements
    • Extension Methods
    • See Also
    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)