Search Unity

Reset Input System Handles/DeviceAssignments

Discussion in 'Input System' started by darthbator, Aug 8, 2016.

  1. darthbator

    darthbator

    Joined:
    Jan 21, 2012
    Posts:
    169
    Hey guys I was wondering if there was a quick and easy way to reset the input system? I'm currently working on cleaning up the game I am working on to loop after the players have played and haven't found an easy way to reset the input system to it's default state. By default I have just one global handle established and nothing else. I was trying to get back to that state but if there's a simple way to just clear all handles and unassign all devices I'll take it! This is what I was using to attempt this but I seem to run into errors when attempting to reset the system in this manner. Help would be most appreciated! Thanks

    Code (CSharp):
    1.     public static void UnbindControls () {
    2.         IEnumerator<PlayerHandle> playerIterator = PlayerHandleManager.players.GetEnumerator();
    3.         List<PlayerHandle> handles = new List<PlayerHandle>();
    4.  
    5.         while (playerIterator.MoveNext())
    6.             if (!playerIterator.Current.global)
    7.                 handles.Add(playerIterator.Current);
    8.  
    9.         foreach (PlayerHandle handle in handles) {
    10.             IEnumerator<InputDevice> deviceIterator = handle.GetApplicableDevices().GetEnumerator();
    11.             List<InputDevice> devices = new List<InputDevice>();
    12.             while (deviceIterator.MoveNext())
    13.                 devices.Add(deviceIterator.Current);
    14.  
    15.             foreach (InputDevice device in devices)
    16.                 handle.AssignDevice(deviceIterator.Current, false);
    17.             PlayerHandleManager.RemovePlayerHandle(handle);
    18.         }
    19.     }