[Solved]OnDeviceLost and OnDeviceRegained events not triggering

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,

 public void OnDeviceRegained()
    {
        Debug.Log("gamepad conected!");
        touchcontrolcanvas.SetActive(false);
    }

    public void OnDeviceLost()
    {
        Debug.Log("gamepad disconected!!!");
        touchcontrolcanvas.SetActive(true);
    }
}

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

Try with

public void OnDeviceRegained(PlayerInput pi)
    {
        Debug.Log("gamepad conected!");
        touchcontrolcanvas.SetActive(false);
    }
    public void OnDeviceLost(PlayerInput pi)
    {
        Debug.Log("gamepad disconected!!!");
        touchcontrolcanvas.SetActive(true);
    }
}

nope, still not working:(

*bump

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.

public void OnControlsChanged(PlayerInput player)
{
    touchcontrolcanvas.SetActive(player.currentControlScheme == "touch");
}

so a gamepad disconnected on purpouse Will not trigger the OnDeviceLost event? oh ok.