The Input Manager is responsible for storing all the input configuration data and making it accessible during runtime. You must always have one Input Manager in the scene or Rewired input will be unavailable.
- You may have one and only one Input Manager in the scene.
- Do not disable or enable the Input Manager during runtime.
Creating an Input Manager
Create an Input Manager in the scene from the menu: Window -> Rewired -> Create -> Input Manager
The Rewired Editor allows you to create and edit input. Launch the Rewired Editor by clicking on the Rewired Input Manager in the scene hierarchy and clicking the "Launch Rewired Editor" button in the inspector. This will allow you to edit the input configuration data stored in the selected Rewired Input Manager.
Configure settings in Rewired Editor - Settings.
Unlike most input systems, Rewired does not store its input configuration data (maps, Actions, etc.) in a single location for the entire project. Instead, the data is stored in the current Rewired Input Manager game object. This means that you can have entirely different input setups for different scenes in your project if you like because each Rewired Input Manager is completely separate. It also means that input data is not globally available, especially in editor scripts or when Rewired has not been initialized.
At runtime, the current input configuration is loaded from the active Rewired Input Manager in the scene. To change to a completely different input configuration, you can disable one Rewired Input Manager and enable another in the editor. (Make sure you only have one active any any time or all others will be disabled.) The Rewired Input Manager can also be made into a prefab and instances placed into each scene for a shared configuration.
When the active Rewired Input Manager is destroyed, it will completely reset Rewired, thereby invalidating Player, Controller, etc. object references, losing controller assignments, etc. Any references to these objects you have in scripts will no longer be valid. You must be aware of this if destroying the Rewired Input Manager, particularly on level loading if "Don't Destroy on Load" is not checked.
Note: This also affects runtime recompiling of scripts in the editor. When scripts are recompiled at runtime, Rewired is reset. Cached references to Rewired objects become invalid at this point, so your scripts may begin to throw null reference exceptions if this is not accounted for. See this link for more information if runtime script recompiling is part of your workflow.
|Don't Destroy On Load||When this is checked, the Input Manager will not be destroyed when a new scene is loaded.|
|Data Files||An object reference to the ControllerDataFiles object. This object contains a list of all supported joysticks and templates and is required for Rewired to function correctly. If you want to customize your own list of supported controllers, you can link this to a separate copy of ControllerDataFiles that you have modified. (See Creating Controller Definitions for more information.)|
|Debug Information||Shows a wealth of useful information during runtime on Players, Controllers, Controller Maps, etc. Allows you to visualize most runtime objects in the system.|
Using the Rewired Input Manager in your game
For finished game builds, the Rewired Input Manager should exist in your initial game scene. Make sure "Don't Destroy On Load" is checked so Rewired will persist throughout the entire game session.
Testing Individual Scenes
If you need to do testing on an individual scene, you can create a prefab (see note below) out of your Rewired Input Manager and place an instance of it in all your scenes, leaving "Don't Destroy on Load" checked. When a new scene is loaded, the additional Rewired Input Manager in the loaded scene will destroy itself automatically leaving the original intact and continuing to handle input without causing any errors.
Another way to achieve a setup that allows for both testing individual scenes at will and advancing through levels in your final game is to create a script that instantiates a prefab of your Rewired Input Manager on Awake. You can put this script on a GameObject prefab instance that you place in every scene of your game. On Awake, your script should check if a Rewired Input Manager already exists in the scene first, and if it doesn't, instantiate it. Leave "Don't Destroy On Load" checked in the Rewired Input Manager. Finally, be sure your script has a very low number set for its Script Execution Order -- it should execute before any other scripts (apart from Rewired's Input Manager) so that Rewired will be set up and ready by the time any other scripts in your game that rely on input make calls to Rewired.
Important Note: If you make a prefab out of the Rewired Input Manager, always open the Rewired Editor on the prefab, not the one in the scene or your changes will be applied to the scene instance. If you do accidentally make changes to the instance in the scene, you can apply the changes to the prefab and everything will be in sync.