Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Simulating virtual InputDevice disconnect events

Discussion in 'Input System' started by Ollie_Palmer, Apr 25, 2021.

  1. Ollie_Palmer

    Ollie_Palmer

    Joined:
    Jun 17, 2019
    Posts:
    10
    Hello,

    I've read through the documentation but can't seem to be able find how to 'force' the input system to disconnect a device.
    I have a device:
    Code (CSharp):
    1. gamepad2 = InputSystem.AddDevice<Gamepad>();
    I've found you can queue events such as:
    Code (CSharp):
    1. InputSystem.QueueEvent(DeviceRemoveEvent.Create(gamepad2.deviceId).ToEventPtr());
    But this is removing a device, which one could do with:
    Code (CSharp):
    1.  InputSystem.RemoveDevice(gamepad2);
    I haven't found anything about disconnecting.

    I just want to disconnect (and eventually reconnect) my virtual gamepads for play testing purposes.
    Help would be much appreciated.
     
  2. Ollie_Palmer

    Ollie_Palmer

    Joined:
    Jun 17, 2019
    Posts:
    10
    Does anyone know the right event to queue?
     
  3. Ollie_Palmer

    Ollie_Palmer

    Joined:
    Jun 17, 2019
    Posts:
    10
    So I have found DeviceLostEvent:
    Code (CSharp):
    1. UnityEvent<PlayerInput> disconnectEvent = new PlayerInput.DeviceLostEvent();
    I just don't know how to queue this event for a particular device...

    Also this doesn't even work in InputTestFixtures since apparently it's 'unsafe context':
    Code (CSharp):
    1. InputEventPtr inputEventPtr = InputEventPtr.From(disconnectEvent);
    2. InputSystem.QueueEvent(inputEventPtr);
    How can I force device disconnects (and eventually reconnect) with virtual gamepads?
    Any help would be much appreciated.
     
  4. Ollie_Palmer

    Ollie_Palmer

    Joined:
    Jun 17, 2019
    Posts:
    10
    Is this not supported by the InputSystem?