# Rewired Standalone Input Module

This is an EventSystem input module component that can be used in place of Unity's StandaloneInputModule. The purpose of this module is to allow Rewired to control navigation of Unity's UI instead of the default UnityEngine.Input.

When you install or upgrade Rewired, it will automatically install the RewiredStandaloneInputModule.cs file in the Rewired/Integration/UnityUI folder provided you are running Unity 4.6 or greater.

This component must be added to the EventSystem in the scene and the default StandaloneInputModule must be disabled or removed. This will allow the UnityUI system to receive input from Rewired. You must also create the appropriate Actions in the Rewired Editor to match the Actions listed in the RewiredStandaloneInputModule and assign these Actions to one or more Controller Maps then assign those to one or more Players.

### Quick Setup

1. Create your Unity UI as per normal practice.
2. Select the EventSystem object in the scene.
3. Disable the StandaloneInputModule component on the EventSystem object.
4. Add the RewiredStandaloneInputModule component to the EventSystem object.
5. Customize the settings on the RewiredStandaloneInputModule if desired.
6. Open the Rewired Editor and create an Action for each of the controls listed in the RewiredStandaloneInputModule. By default, these are "Horizontal", "Vertical", "Submit", and "Cancel." The names you create in the Rewired Editor must match exactly those in the RewiredStandaloneInputModule's inspector. If you'd like to change the names of these Actions, you may do so, but they must match between the Rewired Editor and the RewiredStandaloneInputModule.
7. Create one or more Joystick, Keyboard, or CustomController maps with the Actions you created above assigned to elements.
8. Assign the controller maps map(s) to one or more Player.
9. Adjust the settings in the RewiredStandaloneInputModule to change which Player(s) input is drawn from and other options.

Now your Unity UI should be controlled by Rewired instead of Unity's input system.

### Event System and Component

You can either create a normal Unity Event System and replace the Standalone Input Module with the Rewired Standalone Input Module component or you can create a Rewired Event System from either of the menu items:

- GameObject -> Create Other -> Rewired -> UI -> Rewired Event System
- Window -> Rewired -> Create -> UI -> Rewired Event System

### Rewired Actions

Four Actions must be set up in the Rewired Input Manager and the RewiredStandaloneInputModule in order to control the UI. These four Actions must have names that match exactly in both the Rewired Input Manager and the RewiredStandaloneInputModule.

1. Horizontal Axis - The Action that will control Left/Right movement in the UI.
2. Vertical Axis - The Action that will control Up/Down movement in the UI.
3. Submit - The Action that submits a button.
4. Cancel - The Action that cancels.

The actual names you use are up to you. Of course these Actions must also be assigned to one or more keyboard or joystick maps and assigned to a Player to be functional.

NOTE: It is HIGHLY recommended that you create unique menu-only Actions for these UI controls in a separate controller map category from your game Actions. If you use your in-game actions such as "Move Horizonal" or "Jump" for these UI controls, you run the risk of allowing the user to render the UI unusable because they removed an assignment for one of these game Actions which was also controlling the UI.

The settings in the RewiredStandaloneInputModule will determine which Players can control the UI. If you check "Use All Rewired Game Players", all Players besides the System Player that have a map configured with these UI Actions will be able to control the UI. If you check "Use Rewired System Player", the same will be true for the System Player. If instead you only want specific Players to control the UI, you can set these Player Ids individually.

If the UI control speed with a Joystick seems too slow or fast, adjust the "Input Actions Per Second" setting.

### Rewired Input Manager settings

This image shows the 4 actions that have been set up for controlling the UI.

Unknown Controllers:
It is recommended that you create a map for the Unknown Controller. This way, if a user attaches a controller Rewired does not recognize, they should still be able to control the UI reasonably well.

There is no way to know what axes or buttons will actually be available on these controllers, but you can make some basic assumptions that should allow most controllers to control the UI.

- Axis 0: Map to your "UIHorizontal" Action. (Axis 0 is almost always the horizontal axis on the first joystick)
- Axis 1: Map to your "UIVertical" Action and Invert this axis. (Axis 1 is almost always the vertical axis on the first joystick and is always inverted.)
- Button 0: Map to your "UISubmit" Action.
- Button 1: Map to your "UICancel" Action.

Of course, the above are only recommendations. You can set up your control scheme however you decide.

### Troubleshooting:

Before contacting support for RewiredStandaloneInputModule issues, be sure your issue has to do with Rewired and not just Unity's UI system in general.

1. The RewiredStandaloneInputModule is just a modified version of Unity's open-source StandaloneInputModule. The only changes to it are to make it work with Rewired as the input source. No attempt has been made to enhance this UI system to support multiple simultaneous selection controls (for example, a multi-player character selection screen). That is beyond the scope of this convenience component.
2. The Rewired Standalone Input Module does nothing besides control input in Unity's UI system by changing the underlying input source from UnityEngine.Input to Rewired. If you are having difficulties with controlling the UI, please make sure your problems aren't really pertaining to usage of Unity's UI system before contacting support. I frequently get questions that are actually issues with Unity UI setup and have nothing to do with Rewired. When in doubt, test with the StandaloneInputModule instead of the RewiredStandaloneInputModule. If the problem persists, you know that the issue is not with Rewired but rather something you've missed when setting up Unity UI.

Problem: Receiving duplicate mouse clicks when clicking on a UI button

Do not assign UI Submit or Cancel Actions to Mouse Left Button or Mouse Right Button or you will receive double-clicks evey time the mouse button is pressed over a button. The mouse button click on a UI element is based on mouse cursor position and does not use the Action system.

Problem: Unity UI navigation with joystick or keyboard doesn't work

While this is a general Unity UI usage issue and not a Rewired issue in any way, because I've received so many support requests where this ends up being the answer, I've decided to post it here.

- Unity UI cannot be controlled by keyboard or joystick unless you specify a current or starting Selectable GameObject in the Unity UI EventSystem.

Unity UI requires a Selectable to be selected before any navigation will work for joystick or keyboard, otherwise it has no starting point from which to navigate when you press a key or a stick direction. You must either set the First Selected field in the inspector of the EventSystem component, or set the current selected GameObject via scripting as shown below.

    using UnityEngine.EventSystems;

    void SetSelected(GameObject selectableObject) {
        // Set the currently selected GameObject
        EventSystem.current.SetSelectedGameObject(selectableObject);
    }

Please refer to the Unity documentation for information on how to use Unity UI.

### FAQ:

Does the Rewired Standalone Input Module do _________?

If the Unity StandaloneInputModule doesn't do it, neither does the RewiredStandaloneInputModule.

The RewiredStandaloneInputModule is just a modified version of Unity's open-source StandaloneInputModule. The only changes to it are to make it work with Rewired as the input source. No enhancements have been made to this module.

Please refer to the Unity documentation on the StandaloneInputModule for usage.

Documentation