Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Gamepad.current.SetMotorSpeeds() silently fails when called from Timer_Elapsed

Discussion in 'Input System' started by SpinachSoup, Jan 17, 2021.

  1. SpinachSoup

    SpinachSoup

    Joined:
    Jan 7, 2021
    Posts:
    2
    Example:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3. using System.Timers;
    4.  
    5. public class myBox: MonoBehaviour
    6. {
    7.    private Timer timer = new Timer(500);
    8.    
    9.    void Awake()
    10.     {
    11.        timer.Elapsed += timer_Elapsed;
    12.        timer.Start();
    13.     }
    14.    
    15.    private void timer_Elapsed(object sender, ElapsedEventArgs e)
    16.     {
    17.         Debug.Log("timer_Elapsed, Gamepad.current.SetMotorSpeeds(1f, 1f)");
    18.         Gamepad.current.SetMotorSpeeds(1f, 1f);
    19.     }
    20. }
    21.  
    Expected behaviour:
    The string "StopTimer_Elapsed, Gamepad.current.SetMotorSpeeds(1f, 1f)" is printed
    Game pad vibration is activated

    Actual behaviour:
    The string "StopTimer_Elapsed, Gamepad.current.SetMotorSpeeds(1f, 1f)" is printed
    Game pad vibration is NOT activated

    Notes:
    Not related to the game pad, the game pad vibration is activated as expected when the call to Gamepad.current.SetMotorSpeeds is made from other methods.
     
  2. SpinachSoup

    SpinachSoup

    Joined:
    Jan 7, 2021
    Posts:
    2
    Version: 2019.4.18f1
     
  3. michaeleconomy

    michaeleconomy

    Joined:
    Aug 28, 2018
    Posts:
    58
    I'm doing this in 2019.4.17f1 and it works:

    Code (CSharp):
    1.  
    2.         var gamepad = Gamepad.current;
    3.         if (gamepad != null) {
    4.             gamepad.SetMotorSpeeds(0.25f, 0.75f);
    5.             yield return new WaitForSeconds(0.1f);
    6.             gamepad.SetMotorSpeeds(0, 0);
    7.         }
    8.