Page 1 of 1

[HOWTO] How To: Set Up New Input System

Posted: Wed Apr 07, 2021 8:27 am
by Tony Li
This is a quick how-to that explains how to set up the Dialogue System to use the new Input System.

1. From the Package Manager window, import the new Input System.

2. On the Dialogue System's Welcome Window (Tools > Pixel Crushers > Dialogue System > Welcome Window), tick the USE_NEW_INPUT checkbox:

useNewInputCheckbox.png
useNewInputCheckbox.png (43.94 KiB) Viewed 229 times

3. Write an optional script to tell the Input Device Manager about any inputs that you may have defined in your new Input System actions asset. Make sure you've ticked the actions assets' option to generate a C# script file. The example script below assumes your actions asset has generated a C# script file named MyControls.cs.

The example script below is named RegisterMyControls. It registers two inputs -- "Back" and "Interact" -- so the Dialogue System knows about them:
RegisterMyControls.cs

Code: Select all

using UnityEngine;
using UnityEngine.InputSystem;
using PixelCrushers;

public class RegisterMyControls : MonoBehaviour // Add me to Dialogue Manager.
{
    protected static bool isRegistered = false;
    private bool didIRegister = false;

    void Awake()
    {
        controls = new MyControls();
    }

    void OnEnable()
    {
        if (!isRegistered)
        {
            isRegistered = true;
            didIRegister = true;
            controls.Enable();
            InputDeviceManager.RegisterInputAction("Back", controls.Gameplay.Back);
            InputDeviceManager.RegisterInputAction("Interact", controls.Gameplay.Interact);
        }
    }

    void OnDisable()
    {
        if (didIRegister)
        {
            isRegistered = false;
            didIRegister = false;
            controls.Disable();
            InputDeviceManager.UnregisterInputAction("Back");
            InputDeviceManager.UnregisterInputAction("Interact");
        }
    }
}
Add this script to your Dialogue Manager. If you're using Quest Machine instead of the Dialogue System, add it to your Input Device Manager or Quest Machine GameObject instead.

4. If you're using a Selector or Proximity Selector, set its Use Button to one of the inputs that you've registered, such as "Interact" (without quotes) in the example above. Alternatively, if you've set the Use Key, the Input Device Manager will do its best to translate the key code into a corresponding key definition in the new Input System. This generally works for all standard keyboard keys such as F or Esc.

Re: [HOWTO] How To: Set Up New Input System

Posted: Wed May 19, 2021 11:12 pm
by Tony Li
Video tutorial: