Converting Interactable Legacy Input to the New Unity Input System

Jordan Evans
3 min readFeb 10, 2022

Let’s take a look at how we can go about changing the interaction controls from the legacy input to the new input system. Let’s first start with how we can adjust our code for interactions that are based off a single click of a key:

As we can see from the legacy code, we have a switch statement set up that determines which type of interaction is occurring. We can reuse this switch statement part of the code and just have it called upon when out interact action has started:

What we have done is repurposed the core aspects of the code, but got rid of the need to implement the KeyState status to determine what we want our key action to do. With this in place, let’s see how it works within our game:

From here, what we can do is look at how we will want to get an interaction in which we have to hold down our key for:

In our original code, we have it set up with a keystate that needs to be held, and it calls upon the HoldAction code that has been used. What we can do is just simply add this to the end of our current switch statement, and not worry about having all of this additional code get place:

Now, let’s see how this looks within the game:

Now that we have it charging when held down, there is a small issue in that we keep charging even when letting go of our key. In order to fix this, we can put in the second part of the legacy code for the end functionality into a cancelled function:

With this, it should now stop our charging period and have the player need to restart from the beginning:

Now, let’s take a look at the difference between how the script is set up from legacy to new input:

As we can see, it doesn’t involve having to make sure we are calling the key press in the script, along with state. This makes it much easier to do the same actions as before.
Now that we have this all set up, we are almost done experimenting changing from a legacy input system to the new input system.

--

--