Click the video to watch.

New Input System

If you use New Input System, you can make a button check in a much different way: There is no if-statement, you need an input action asset.

But how to check if you press a button?

That’s very simple! First of all, the New Input System doesn’t have the same if statement to detect if a button is pressed, as it was the case with the old input system. Instead, you should add an input actions asset and make a set of actions that can be part of the input system. This is how an input action window looks like:

Inside, you need to add a layer and an action that will be performed when you press the button. I will choose space bar, but you can choose any other key if you want. Now you need a script. Inside that script, you need to introduce the Input System.

You also need the input action to make sure that it is the reference to that action. After defining the input system you need the OnEnable and OnDisable voids. These voids will define a new function: Test. The test function will have a line of code that checks if you perform the action. There is also a line that will send a message that will tell that it’s working. This gallery consists of the things that you should consider:

If you encounter the error NullReferenceException, this is because you haven’t called the input system in void Awake, which happens immediately when the game is launched. However, the lines that introduce the void Test need to look like this:

Indie Game Services

If you have an indie game project that you need help with, feel free to contact me. You can contact me by sending a DM on Instagram. I already work for clients and their projects are amazing!


Leave a Reply

Your email address will not be published. Required fields are marked *