Device Type Enum and all possible names

Hi,

Why there’s no device type enum in new input system? Like KeyboardAndMouse, XBox, Swtich, Generic

So I have to implement this myself, but how should I know all possible names of devices? Like, XBox controller on PC has name XInputControllerWindows, then on xbox it’ll be XInputControllerXbox? Or just XInputController? I don’t know… What about other controllers?

I want to create system that displays icon based on what device you are currently using, but it’s hard not knowing what device it might be.

Where I can get all possible names for these devices?

Thanks!

1 Like

Anyone?

Most likely you will have to simply set up a scene that tells you the name of controllers when they use input and then use selection statements depending on what device the game plays on.

You’ll be looking for non-static member in InputDevice, description which is a struct that contains the string deviceClass. That should tell you the name of all the devices.

https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.InputDevice.html

This should tell you more.

There’s no complete list of possible device types that could be collected in an enum. The new Input System is extensible, so you can add your own devices or packages can add them (e.g. Unity’s console packages bring in device types to support their controllers natively or someone could make an open source package with support for additional devices). Enums cannot be extended, so Unity would have to somehow maintain all possible devices and there could be conflicts when multiple device implementations use the same enum value.

The Input System also supports inheritance. There’s e.g. a generic Gamepad device, a generic DualShockGamepad device for all PlayStation gamepads and specific implementations for the various DualShock gamepads generations and different connection types. This really doesn’t map well to a flat enum representation.

Instead, the Input System uses devices and layouts to represent this hierarchy. I would base a system that matches icons to inputs in your game on these layouts. There is InputAction.GetBindingDisplayString that will give you a display string for an action as well as the device layout name and control path it’s bound to. As the documentation indicates, this information is specifically intended to match icons to the controls the action is bound to. You can use InputSystem.IsFirstLayoutBasedOnSecond or InputSystem.LoadLayout to query the layout hierarchy. This way you can e.g. define the four PlayStation button icons for the generic DualShockGamepad layout but the start/select or share/options icons only for the generations they apply to.