Search Unity

[Solved]OnDeviceLost and OnDeviceRegained events not triggering

Discussion in 'Input System' started by Aokkii, Jan 18, 2020.

  1. Aokkii

    Aokkii

    Joined:
    Nov 3, 2013
    Posts:
    118
    I'm trying to use these two events to change between using a canvas with touchscreen buttons, and not using it and use the gamepad.



    the problem is that the events dont get triggered,

    Code (CSharp):
    1.  public void OnDeviceRegained()
    2.     {
    3.         Debug.Log("gamepad conected!");
    4.         touchcontrolcanvas.SetActive(false);
    5.     }
    6.  
    7.     public void OnDeviceLost()
    8.     {
    9.         Debug.Log("gamepad disconected!!!");
    10.         touchcontrolcanvas.SetActive(true);
    11.     }
    12. }
    is this the correct way of doing it?

    i'm using the player input component and the send messages behavior, actions events Works fine, but those two don't.


    device: xinput Xbox 360 controller
     
    Last edited: Jan 19, 2020
  2. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    992
    Try with

    Code (CSharp):
    1. public void OnDeviceRegained(PlayerInput pi)
    2.     {
    3.         Debug.Log("gamepad conected!");
    4.         touchcontrolcanvas.SetActive(false);
    5.     }
    6.     public void OnDeviceLost(PlayerInput pi)
    7.     {
    8.         Debug.Log("gamepad disconected!!!");
    9.         touchcontrolcanvas.SetActive(true);
    10.     }
    11. }
     
  3. Aokkii

    Aokkii

    Joined:
    Nov 3, 2013
    Posts:
    118
    nope, still not working:(
     
  4. Aokkii

    Aokkii

    Joined:
    Nov 3, 2013
    Posts:
    118
    *bump
     
  5. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Might be misunderstanding what you're going for here, but note that the message do not get sent when the player switches devices but rather are used only if the player unexpectedly loses a device. OnDeviceLost is fired when an actively paired device is disconnected and OnDeviceRegained is fired when it comes back. The intention here is to deal with situations such as a gamepad run out of juice.

    In 1.0.0-preview.4 there's a new OnControlsChanged message. Might work for what you're looking for.

    Code (CSharp):
    1. public void OnControlsChanged(PlayerInput player)
    2. {
    3.     touchcontrolcanvas.SetActive(player.currentControlScheme == "touch");
    4. }
    5.  
     
  6. Aokkii

    Aokkii

    Joined:
    Nov 3, 2013
    Posts:
    118
    so a gamepad disconnected on purpouse Will not trigger the OnDeviceLost event? oh ok.