# Unity Input Override

The Unity Input Override script reroutes calls to Unity input from most scripts over to Rewired. Simply install it and every script that calls Input.GetButton, Input.GetAxis, etc. will now use Rewired instead of Unity input. This allows you to use Rewired for input without having to change any code in the scripts. This will even work for most assets downloaded from the Unity Asset Store, allowing you to use Rewired as the input source instead of Unity input.

Usage

- Install the Unity Input Override script.
- Set up Actions in the Rewired Input Manager with names equivalent to the Action names expected by your scripts.
- Create controller maps, Players, etc. using these Actions as per standard Rewired practice.

Here is a simple example of a script that calls Input.GetButtonDown which will be rerouted to Rewired:

    using UnityEngine;
    using System.Collections;

    public class MyClass : MonoBehaviour {

        public void Update() {
            // This call to Input.GetButtonDown will now go to Rewired instead
            if(Input.GetButtonDown("Fire")) {
                // shoot a bullet
            }
        }
    }

Several global settings can be changed at runtime in UnityInputOverride:

    // Get or set the enabled state of the override.
    UnityInputOverride.enabled = false; // if disabled, Input calls route to UnityEngine.Input
    UnityInputOverride.enabled = true; // if enabled, Input calls route to Rewired

    // Get or set the current Rewired Player
    UnityInputOverride.playerId = 2; // change the Rewired Player Id so that input is retrieved from a different Rewired Player

How it works

Unity Input Override script takes advantage of the fact the compiler gives higher priority to classes in the global namespace when resolving references. Therefore, because the Unity Input Override class is named "Input" and is in the global namespace, it takes precendence over UnityEngine.Input. The compiler will now prefer Input (the Rewired class) over UnityEngine.Input when resolving references in scripts that make calls to Input.GetAxis, Input.GetButton, etc.

The CS file is installed in the Plugins folder so it can be accessed by all C#, Unity Script, and Boo scripts.

Limitations

There are some limitations to this system however.

1. The input script must make all calls by using the shortened form of "Input.GetAxis" instead of the fully-qualified form "UnityEngine.Input.GetAxis". Scripts that use fully-qualified calls cannot be rerouted to Rewired because the compiler is explicitly instructed which Input class to use.
2. Calls to Unity input from within DLL's cannot be rerouted.
3. Calls to Input.GetKey or Input.GetKeyDown will not benefit from Rewired's Action-based system.

Notes

- Mouse Sensitivity: If the script you are using processes Mouse X/Y axis values such as a mouse-look script, be sure to set the Mouse XY Axis Sensitivity in the Input Behavior assigned to the Actions to 0.1 instead of Rewired's default value of 1. Unity defaults to 0.1 sensitivity for mouse axes, so you should change this value to match if you want the scripts to behave the same way they would when using Unity input.
- UnityEngine.Input contains the property "location" which returns a LocationService object. Because UnityInputOverride mirrors all properties and methods of UnityEngine.Input, it includes a property for location. The catch is, the mere presence of this code even when there are zero actual calls to it causes Unity to automatically add the Location permission requirement to your application on some platforms (Android is known to do this at present.) If your game does not need the Location permission, this line of code must be removed from UnityInputOverride. You can disable support by by setting "Disable UnityInputOverride LocationService Support" in the Rewired Global Options window which can be found at: Window -> Rewired -> Global Options. Note that this option applies to the current build target group that is selected in the Unity Build Settings window. To set this option for multiple build targets, you must set it for each by selecting the build target group, then setting the option.

Installation

Install the script from the menu:

- Window -> Rewired -> Extras -> Unity Input Override -> Install

This will install one file in the following location:

- Plugins/Rewired/UnityInputOverride.cs file

Uninstallation

Delete the Plugins/Rewired/UnityInputOverride.cs file.

Or you can disable the script for the current platform by adding REWIRED_DISABLE_UNITY_INPUT_OVERRIDE to the custom Scripting Define Symbols in the Unity Player settings.

Documentation