Skip to content

Input

Every script in RPG Map Editor reads the keyboard, mouse and touch screen through one static class, RpgInput. This page covers which input backends it works with, what it supports under each, and how to use it from your own scripts.

Concept

Unity has two input systems: the old Input Manager and the Input System package. A project picks one, or both, in Edit > Project Settings > Player > Other Settings > Active Input Handling.

RpgInput (Scripts/Utils/RpgInput.cs) is compiled against whichever one is on, so the same scripts run with any of the three settings:

Active Input Handling What RpgInput uses
Input Manager (Old) The old Input Manager.
Input System Package (New) The Input System package.
Both The old Input Manager, so the axes your project already set up in Project Settings > Input Manager keep working.

The asset never calls UnityEngine.Input directly. The player controllers, the vehicles, the teleporters, the touch controls, the in-game map editor and RpgMapHelper all go through RpgInput.

Note

Input System Package (New) and Both need the Input System package installed. Unity offers to install it when you switch the setting.

What works under the Input System package

With the old Input Manager, every call passes straight through, so any axis or key your project defines works.

With the Input System package there is no axis table to look names up in, so RpgInput maps them itself:

  • Axes. GetAxis supports three names. Horizontal reads the right and left arrows or D and A. Vertical reads the up and down arrows or W and S. When no key is pressed, both read the gamepad's left stick. Mouse ScrollWheel reads the mouse wheel, scaled to about 0.1 per notch like the old axis. Any other name returns 0 and logs a warning, once per name.
  • Keys. Keys are read from the keyboard by KeyCode. Return, the Control keys and the keypad keys are translated to their Input System names, and the rest match by name.
  • Mouse and touch. Mouse buttons 0 to 4 and the pointer position work, and so do touch count, touch position and touch end.

Keyboard axes under the package are digital: exactly -1, 0 or 1, with no smoothing. With its default settings the old Input Manager ramps its axes up and down, so movement feels slightly different between the two.

Using RpgInput in your scripts

Call it wherever you would call Input. Doing so keeps your scripts working if you, or the buyer of your game template, switch input systems later.

using UnityEngine;
using CreativeSpore.RpgMapEditor;

public class InteractKey : MonoBehaviour
{
    void Update()
    {
        // Same arrow keys and WASD the player uses
        Vector2 move = new Vector2(RpgInput.GetAxis("Horizontal"), RpgInput.GetAxis("Vertical"));

        if (RpgInput.GetKeyDown(KeyCode.E))
        {
            Debug.Log("Interact, facing " + move);
        }

        if (RpgInput.GetMouseButtonDown(0))
        {
            Vector3 world = RpgMapHelper.GetMouseWorldPosition();
            Debug.Log("Clicked tile " + RpgMapHelper.GetTileIdxByPosition(world));
        }
    }
}

The full list of members:

Member What it returns
GetKey(KeyCode) True while the key is held.
GetKeyDown(KeyCode), GetKeyUp(KeyCode) True on the frame the key goes down or up.
GetKeyDown(string) The same, with the key named as a string, like "j". Under the package the name must match a KeyCode name, ignoring case.
GetMouseButton(int), GetMouseButtonDown(int), GetMouseButtonUp(int) Mouse button state. 0 is left, 1 right, 2 middle.
mousePosition Pointer position in screen pixels.
GetAxis(string) An axis value. See the limits above under the package.
touchCount How many touches are active.
GetTouchPosition(int), GetTouchEnded(int) Position of a touch, and whether it ended this frame.

For anything beyond these, like an action map or a second gamepad, read the Input System directly in your own scripts. RpgInput only covers what the asset itself needs.

Keys the framework uses

Key Where
Arrow keys, WASD Walk (Horizontal and Vertical axes). PlayerTileMovement steps with the arrow keys only.
J, H, K, U Shoot down, left, right, up.
Enter (Return) Board or leave a vehicle. Use a teleporter (its Activation Key).
Left click or tap Walk to a spot, on the PlayerTouch prefab.
R Reload the scene, in the demo scene menu.