A wrapper for Unity's "new" input system to make usage simpler and more convenient with a foolproof and more readable API.
Requires com.unity.inputsystem and com.unity.addressables. The minimum required com.unity.inputsystem
version is due to bugs in some core functionality of earlier versions of that package.
Install via the Package Manager using Add package from git URL, or by adding these entries to your project's Packages/manifest.json:
"com.nptp.unity-source-gen": "https://github.com/NPTP/UnitySourceGen.git", "com.nptp.unity-input-system-wrapper": "https://github.com/NPTP/UnityInputSystemWrapper.git"
Both are required. Unity's Package Manager cannot resolve a git URL listed inside another package's dependencies, so com.nptp.unity-source-gen has to be added to your project manifest yourself, before or alongside this package.
com.unity.addressables comes from Unity's registry and is resolved automatically, so it needs nothing from you.
Then run Input > Regenerate Input Wrapper Code and Assets. This creates Assets/ISW.Generated/, containing:
- the generated API (
ISW, the actions classes, theControlSchemeandInputContextenums), in its own assembly Resources/, holding your own editable copy ofInputDataBindingData/, holding a binding data asset per device and a folder of entry assets for each, reached through Addressables rather than Resources
The copies inside the package are read-only defaults, and are only used to seed your project the first time. Both folders are yours to commit or to gitignore and regenerate.
Everything you need is under Input in the menu bar, which is the easiest way to reach the assets worth editing:
- Input > Regenerate Input Wrapper Code and Assets rebuilds the generated API and creates any project assets that are missing. Run it after changing your input action asset, your input contexts, or your control schemes.
- Input > Input Data selects your
InputDataasset, where the input action asset, input contexts, custom setups, binding settings and event system actions are all authored. - Input > Binding Data > ... selects the binding data asset for one device, where you give each of that device's controls a display name and a sprite. This submenu is generated, so it lists exactly the devices your control schemes use.
- Input > Input Wrapper Debugger Window opens a play-mode window showing the first player's current control scheme, current input context, the maps that context has active, and the last few contexts it moved through with the frame each change happened on.
- Subscribe to any player's input events at any time in Awake or later without running into race conditions or null references. Don’t need to know whether the player exists or not. In singleplayer mode, the API is automatically simplified so you don’t even need to specify which player.
- Prevents double subscriptions to any input events.
- Easy player join mode for joining new devices and pairing to under-the-hood input players.
- API is auto-generated by changes to actions/settings such that input events & polling are accessible in the most quick, easily-readable, boilerplate-free (and string-literal-free!) way. Only the methods & properties needed for your game are exposed from the internal assembly to keep things simple. Any changes to your input action asset will be immediately reflected in the generated API so you can fix any broken usage immediately without hunting for broken references or out-of-date strings.
- Switching devices on one player, joining new players on new devices, handling keyboard text input, rebinding controls, updating UI text & sprites for changing controls/devices, and more, are already handled for you requiring only simple subscriptions to the API, with direct access checks also available if you don't want to or can't use the events.
- All input actions are centralized for a single source of truth for all input, even when using input action references (via the new ActionReference) in the inspector, so that you know exactly where your input is coming from across your whole project, and can predict how it will behave when enabled/disabled/subscribed/polled/rebound.
- Dealing with a jungle of input maps turned on and off at any given time is no longer a worry with the new InputContext concept that collects maps in groups. InputContexts can be added, changed & removed quickly in the settings, which then become immediately available in your code. You can even specify particular actions for the event system to use, per InputContext.
- Easy component and API usage to handle rebinding controls for multiple devices.