UserManagement.md 5.5 KB

User Management

The Input System supports multi-user management through the InputUser class. This comprises both user account management features on platforms that have these capabilities built into them (such as Xbox and PS4), as well as features to manage Device allocations to one or more local users.

Note: The user management API is quite low-level in nature. The stock functionality of PlayerInputManager (see Components) provides an easier way to set up user management. The API described here is useful when you want more control over user management.

In the Input System, each InputUser represents a human interacting with the application. For example, you can have multiple users playing a game together on a single computer or device (local multiplayer), where each user has one or more paired Input Devices. A user might be associated with a platform user account, if the platform and Devices support it.

The PlayerInputManager class uses InputUser internally to handle users.

Device pairing

You can use the InputUser.PerformPairingWithDevice method to create a new InputUser instance and pair it with an InputDevice. You can also optionally pass in an existing InputUser instance to pair it with the Device, if you don't want to create a new user instance.

To query the Devices paired to a specific InputUser, use InputUser.pairedDevices. To remove the pairing, use InputUser.UnpairDevice or InputUser.UnpairDevices.

Initial engagement

After you create a user, you can use InputUser.AssociateActionsWithUser to associate Input Actions to it, and use InputUser.ActivateControlScheme to associate and activate a Control Scheme. You can use InputControlScheme.FindControlSchemeForDevice to pick a control scheme that matches the selected Actions and Device:

var scheme = InputControlScheme.FindControlSchemeForDevice(user.pairedDevices[0], user.actions.controlsSchemes);
if (scheme != null)
    user.ActivateControlScheme(scheme);

When you activate a Control Scheme, the Input System automatically switches the active Binding mask for the user's Actions to that Control Scheme.

Loss of Device

If paired Input Devices disconnect during the session, the system notifies the InputUser class. It still keeps track of the Device, and automatically re-pairs the Device if it becomes available again.

To get notifications about these changes, subscribe to the InputUser.onChange event.

User account management

The Input System can associate a user with a platform-specific user account, if both the platform and the Devices support this. Consoles commonly support this functionality. Platforms that support user account association are Xbox One, PlayStation 4, Nintendo Switch, and UWP.

Use the platformUserAccountHandle property to query the associated user account for an InputUser. This property gets determined when the user is first paired to a Device, and the Device has any platform user information the Input System can query.

The account associated with an InputUser might change if the player uses the platform's facilities to switch to a different account (InputUser.onChange receives an InputUserChange.AccountChanged notification).

Note that for WSA/UWP apps, the User Account Information capability must be enabled for the app in order for user information to come through on input devices.

Debugging

Check the debugger documentation to learn how to debug active users.