Upgrading Forklift Controls from Legacy Input to the New Input System
New Input System Framework
Objective: Learn how to upgrade forklift controls from Unity’s Legacy Input System to the New Input System.
This documentation is part of the Software Engineering Framework developed by Game Dev HQ.
We’ll jump straight into upgrading the existing forklift control code. If you’re new to the New Input System, check out these helpful resources first
💡 Need help setting up Input Actions Scripts? Click here
💡 New to the Input System? Start here.
Table of contents
· Enabling Forklift Input
· Disabling Forklift Input
· Driving the Forklift
∘ Calculating the Movement
∘ Registering the Movement
∘ Forklift Movement Result
· Lift Movement
∘ Lift Movement Result
Enabling Forklift Input
For starters, we have to let our game know that we’re switching controls from Player mode to Drive Mode, luckily, the legacy code has a function that allows us to transition into drive mode already.
🔍Code Highlights
- The
EnterDrivetMode()method is responsible for switching control from the player to the forklift. - This is the ideal place to initialize forklift-specific input using the New Input System.
Initialize Forklift Input in the Input Manager
All input logic is handled in a centralized Input Manager Script. This keeps things modular and clean.
💡 Want to learn more about the Input Manager? Check out:
The Best Way to Organize Input Scripts
🔍Code Breakdown
- We create a public method in the Input Manager that handles forklift input initialization.
- The player input is disabled through the Input Actions reference.
- The forklift input is then enabled from the same reference.
- Reference the Input Manager object in the Forklift Script through the Inspector.
- Finally, call this method inside the drone’s
EnterDriveMode()method.
Disabling Forklift Input
To properly exit forklift control, we need to:
- Detect when the Exit key is pressed
- Disable forklift controls on that press
- Re-enable player controls once the forklift is exited
Add an Exit Event
In your InitializeForkliftInput() method within the Input Manager, use Unity’s callback system to subscribe to the Exit action. This event will register when the exit input is performed and trigger the handoff from forklift to player controls.
💭 Note: When using event notation, remember to press Tab to auto-generate the callback method. The
ExitVehicleaction comes from our Forklift action map. If you’d like to learn more about creating action maps, check out this guide.
Disable Method
To keep the code organized, let’s create a DisableForklift() method inside our Input Manager script. This method will simply disable the Forklift controls and re-enable the Player controls using our input action references.
Now, we call this method from our exit event.
Since the legacy code already includes an ExitDriveMode method, we’ll call it from our Input Manager script when the exit key is pressed. This ensures the method runs correctly under the new Input System, as the legacy implementation originally relied on validating a boolean value tied to the old input checks.
Legacy Code:
New Input System
Driving the Forklift
In the legacy code, several functions and validations were handled directly within the Update method. With the New Input System, we streamline this process, reducing much of that overhead.
Let’s take a look at them one by one and upgrade them to the New Input System.
Calculating the Movement
The first type of movement we’ll be addressing is how the forklift moves when driven.
🔍Code Highlights
- The method has been updated to public so it can be called from the Input Manager Script.
- A parameter variable
Vector2 inputValuewas added, which will be assigned within the Input Manager Script. - The Horizontal and Vertical inputs have been replaced with the corresponding X and Y values from
inputValue. - The remaining movement calculations remain unchanged, as they are not affected by the upgrade.
Registering the Movement
In the Input Manager Script, we have added the following code:
🔍Code Highlights
- A variable
forkliftMoveis created as a context variable, which captures the input. - Using
ReadValue<Vector2>(), the user’s input is registered and stored as a movement value. - We then call the public
CalculateMovementmethod from the Forklift script, passing inforkliftMoveas a parameter. - This ensures the method processes the player’s input directly when performing its calculations.
Forklift Movement Result
The Forklift is now fully functional with the New Input system.
Lift Movement
The lift movement saw the greatest reduction in code out of all the upgrades.
Originally, the Lift Controls were registered using multiple GetKey checks.
Then we have a lengthy set of coroutines that handle the up-and-down movement of the lift.
For the upgrade, I commented out the old implementation and refactored everything into a single, streamlined method called LiftRoutine. While not a coroutine itself, it encapsulates a condensed version of the logic the coroutines previously handled — hence the name.
🔍Code Highlights
- We created a public method with a
floatparameter, designed to be called and assigned from the Input Manager Script. - The lift’s temporary position (
tempPos) is now calculated relative to theliftInputvariable, which updates dynamically based on user input. To prevent overshooting or unintended behavior, the values are clamped between defined lower and upper limits.
Finally, in the Input Manager Script, just three simple lines of code are enough to tie everything together.
🔍Code Highlights
- We introduced a variable called
liftInput, which reads and stores the user’s input value. - In this case, we’re working with 1D input from the action map. This input type returns a value between -1 and 1, so the condition
if (liftInput != 0)is only true when input is actively registered. - When the
LiftRoutinepublic method is called from the Forklift script, theliftInputvariable is passed as its parameter. Depending on whether the value is positive or negative (between -1 and 1), the lift moves up or down accordingly.
Lift Movement Result
Your Forklift input is now modular, optimized, and ready!
Achievements:
✅Clean separation between input logic (Input Manager) and Forklift behavior (Forklift Script)
✅ Refactored methods that are scalable, readable, and easy to manage
✅ A fully functional Forklift controller powered by Unity’s New Input System
Thanks for reading!
If you found this guide helpful, feel free to check out my portfolio or follow me — I’m currently open to opportunities in the video game industry! 😊
