Two Input Systems
Part of the Building Real Games section of Coddy's Unity journey. Lesson 43 of 56.
Unity has two ways to read the keyboard and mouse. The one you have used so far is the Input Manager: the Input class with GetKey, GetAxis and GetButtonDown, and axes and buttons named in Project Settings > Input Manager. The newer one is the Input System package (com.unity.inputsystem). Its scripts start with using UnityEngine.InputSystem;, and it reads devices as objects, such as Keyboard.current and Mouse.current, and through actions: named things the player does, such as Move and Jump, each bound to keys, sticks and buttons.
Which one a project uses is a Player setting: Edit > Project Settings > Player > Other Settings > Active Input Handling, with three choices: Input Manager (Old), Input System Package (New) and Both. A new Unity 6 project starts on Input System Package (New), and there every call to the Input class throws an InvalidOperationException that says you are reading input through UnityEngine.Input while the project uses the Input System package. That is why the earlier lessons asked you to pick Both. Changing it needs an editor restart, which Unity offers to do.
Unity 6 starts with the new system because one API covers keyboards, mice, gamepads, touch screens and XR controllers, and because actions keep the keys out of the code: a script reads the Jump action, and the same line works for Space, a gamepad's A button or a phone's on-screen button, and for a player who rebinds the key. The old Input Manager stays for older projects. Coddy's game view works like Both, so the keys, clicks and the phone's pad (arrows and Jump) reach both systems. The rest of this chapter uses the Input System.
Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Building Real Games
2Buttons and Screens
Buttons and onClickLambdasWiring in the InspectorPanels On and OffHealth BarsRecap: Upgrade Shop5Saving with PlayerPrefs
Save a NumberLoad with a DefaultHigh ScoreSave SettingsRecap: Coins in the Bank3The Game Manager
One Script Runs the GameThe SingletonGame StatesSwitching on the StateRecap: Round Manager6Project: Endless Runner
Three LanesObstacles Ahead9The New Input System
Two Input SystemsKeyboard and MousePressed This FrameInput ActionsRecap: Input Swap