CodeBlanks Logo Icon CodeBlanks

The Input System package

Learn to add the new Input System package to the project.

Why the new Input System exists

The old Input class is enough for small games but falls short for games that need multiple devices such as gamepad and touch. The new Input System package lets you define input independently of the device and is installed from Window > Package Manager > Unity Registry.

using UnityEngine.InputSystem;

if (Keyboard.current.spaceKey.isPressed)
{
    Debug.Log("Bosluk basildi");
}

After the install you reach devices directly through the Keyboard, Gamepad and Mouse classes.

Enabling it after installation

When the package is installed Unity offers to switch the active input handling and restarts the editor. The same choice lives under Edit > Project Settings > Player > Active Input Handling. The options are Input Manager (Old), Input System Package (New) and Both; Both means both systems run at the same time.

using UnityEngine.InputSystem;

if (Gamepad.current != null)
{
    Debug.Log("Gamepad bagli");
}

Practice Compute the active input handling

Write a MonoBehaviour named GirdiAyari. Add two bool fields called eskiKullan and yeniKullan and set both to true. In Start handle three cases: if both are true assign Both, if only yeniKullan is true assign Input System Package (New), otherwise assign Input Manager (Old) to the ayar variable. Finally call Debug.Log(ayar).

Starter code

Player.cs
using UnityEngine;

public class GirdiAyari : MonoBehaviour
{
    bool eskiKullan = true;
    bool yeniKullan = true;

    void Start()
    {
        string ayar = "";

        // eskiKullan ve yeniKullan degerlerine gore uc durumu ele al
        // iki deger de true ise birlesik secenegi ata
        // yalnizca yeniKullan true ise yeni paket secenegi ata
        // diger durumda eski yonetici secenegi ata

        Debug.Log(ayar);
    }
}

Sample solution

Player.cs
using UnityEngine;

public class GirdiAyari : MonoBehaviour
{
    bool eskiKullan = true;
    bool yeniKullan = true;

    void Start()
    {
        string ayar;

        if (eskiKullan && yeniKullan)
        {
            ayar = "Both";
        }
        else if (yeniKullan)
        {
            ayar = "Input System Package (New)";
        }
        else
        {
            ayar = "Input Manager (Old)";
        }

        Debug.Log(ayar);
    }
}

Expected output

Both

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Where is the new Input System package installed from?

  • It is installed from the Package Manager, Unity Registry list Correct answer
  • It is enabled under Player Settings > Quality
  • It is downloaded from the Asset Store
  • It is added from the Build Settings window

Explanation: The Input System is an official Unity package; select Input System under Window > Package Manager > Unity Registry and press the Install button.

2 Complete the active input handling value

Question
string ayar = "____";
Answer
string ayar = "Both";

Explanation: When old and new input run together the Active Input Handling value is Both; the single-system values do not cover that case.

3 Installation terms

Term Meaning
Unity Registry The official list of packages
Install Adding the selected package to project
Active Input Handling Choosing which input system runs
Both Old and new input running together

All lessons in Advanced