Refactor game input to use Unity's new Input System package #27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
JIRA Ticket
Changelog
PlayerInputActions
assetGameInput
MonoBehaviour for encapsulating player inputPlayerController
andPlayerShoulderTarget
to rely onGameInput
valuesSettings/
for tidinessHow it works
There's an opportunity cost between learning the new Input System, and moving onto bigger and greater things (like coding the meat of the game's gameplay systems), but I wanted to do things the 2023 way in Unity.
So I spent the last day learning Unity's new Input System package. While there are many online that complain about how complex it is to use, I thought it clicked pretty quickly.
The issue with Unity tutorials is that you need to find the good stuff amidst all the well-intentioned (but non-ideal) YouTube tutorials out there. After some false starts, I found an official Unite Copenhagen talk from Unity to be the best resource for learning the Input System's why and how:
The Input System 1.5.0 documentation is also far better than previous versions, and simply reading the first few paragraphs of each page gives you a good bird's eye view of the package’s capabilities, leaving the details of UI/API properties for later reading if needed.
If I had to summarize Input System's primary benefits, they'd be:
Input.GetAxis(“HorizontalKeyboard”)
andInput.GetAxis(“HorizontalJoystick”)
), Input System adds a layer of abstraction called “actions”, and you “bind” inputs to these actions at editor time and runtime.Update()
; instead, you attach inputs toEventHandlers
in C#. This is awesome; C# events serve as a great communication mechanism between MonoBehaviours and ScriptableObjects.Generate C# Code
button that generates a C# class from yourPlayerInputActions
asset, so that you can reference action names as C# properties. If you make a typo, the compiler complains so you can fix your bug early.But more than anything, it's just really cool to see your game played with an Xbox controller. 😄
Highly recommend migrating over. Watch the Unite Copenhagen talk to get started, then jump right in for one of your Unity projects.
Quality Assurance
Look Mom, Dad — I'm making games! 😁