Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Identify virtual device

Discussion in 'Input System' started by nraw, Jan 8, 2023.

  1. nraw

    nraw

    Joined:
    Feb 6, 2015
    Posts:
    3
    Is there a way to identify that a device assigned is virtual?
    I'd like to understand when the player is controlled with the gamepad that was created for the on-screen buttons
     
  2. rdjadu

    rdjadu

    Joined:
    May 9, 2022
    Posts:
    114
    Those devices in particular have the "OnScreen" usage tagged onto them. For example, in a binding "<Gamepad>{OnScreen}/buttonSouth" would specifically bind only to a gamepad created from on-screen controls.

    In the API, you can query that from the
    InputControl.usages
    property.

    Code (CSharp):
    1. if (device.usages.Contains(x => x == "OnScreen"))
    2.    Debug.Log("On-Screen Device!");