LibraryUnderstanding Input Actions and Input System

Understanding Input Actions and Input System

Learn about Understanding Input Actions and Input System as part of AR/VR Development with Unity XR

Understanding Input Actions and the Input System in Unity XR

In Extended Reality (XR) development with Unity, the XR Interaction Toolkit provides a robust framework for handling user input across various XR devices. At its core lies the Input System, which abstracts the complexities of different input methods, allowing you to create a unified input experience for your applications.

The Unity Input System: A Foundation for XR Interaction

The Unity Input System is a powerful package that allows you to define, manage, and process input from a wide range of devices. It's designed to be flexible and scalable, supporting everything from keyboard and mouse to VR controllers and motion trackers. For XR development, it's crucial for translating physical actions into digital commands within your virtual environment.

Input Actions map device inputs to logical game actions.

Input Actions are the bridge between raw device input (like a button press) and the conceptual actions your game understands (like 'Jump' or 'Grab'). This abstraction makes your input handling device-agnostic.

Input Actions are defined in an 'Input Actions Asset' (.inputactions file). Within this asset, you create Action Maps, which group related actions. Each Action can have multiple Bindings, connecting specific device controls (e.g., 'Left Controller/Trigger Button') to the logical action (e.g., 'Primary Action'). This allows you to easily rebind controls or support different input devices without changing your core game logic.

Key Components of the Input System

The Input System relies on several key components to function effectively:

  1. <b>Input Actions Asset:</b> A ScriptableObject that defines your input scheme. It contains Action Maps, Actions, and Bindings.
  1. <b>Input Action Manager:</b> A component that manages the Input Actions Asset and handles the flow of input events.
  1. <b>Player Input Component:</b> A MonoBehaviour that links an Input Actions Asset to a player and listens for input events, triggering corresponding Unity events or callbacks.
  1. <b>Input Processors and Interactions:</b> These allow you to modify or filter input data (e.g., dead zones for analog sticks) or define complex input behaviors (e.g., holding a button).
What is the primary purpose of an Input Actions Asset in Unity?

To define and organize input schemes, including Action Maps, Actions, and Bindings, which map device inputs to logical game actions.

XR Interaction Toolkit and Input Actions

The XR Interaction Toolkit leverages the Input System to provide pre-configured Input Actions for common XR interactions. These include actions for locomotion (teleportation, continuous movement), grabbing objects, UI interaction, and controller button presses. You can customize these or create your own to suit your project's specific needs.

The XR Interaction Toolkit provides a set of default Input Actions, often organized into Action Maps like 'XRI_LeftHand' and 'XRI_RightHand'. These maps contain actions such as 'Move', 'Turn', 'Teleport Select', 'Teleport Activate', 'Grip', and 'Trigger'. Each action can have multiple bindings to accommodate different XR controllers (e.g., Oculus Touch, Vive Controllers). This abstraction allows developers to write input logic once and have it work across various XR hardware.

📚

Text-based content

Library pages focus on text content

Implementing Input Handling

To use Input Actions in your XR project, you typically:

  1. <b>Install the Input System Package:</b> Ensure the Input System package is installed via the Package Manager.
  1. <b>Create an Input Actions Asset:</b> Create a new Input Actions asset and define your Action Maps and Actions.
  1. <b>Assign the Asset:</b> Assign this asset to a Player Input component in your scene.
  1. <b>Handle Input Events:</b> Write scripts to subscribe to input events (e.g.,
    code
    action.performed += context => MyFunction();
    ) or use the
    code
    PlayerInput
    component's event broadcasting.

The XR Interaction Toolkit's XR Controller component often automatically reads input from the Input System based on its assigned Action Map, simplifying the process for common XR interactions.

Benefits of Using Input Actions

Using the Input System and Input Actions offers several advantages for XR development:

FeatureBenefitImpact on XR
AbstractionDecouples input logic from specific hardware.Enables cross-platform XR support without major code changes.
FlexibilityEasy to rebind controls and add new input devices.Allows users to customize controls and supports a wider range of VR/AR hardware.
ReadabilityInput logic is defined in a clear, organized asset.Improves project maintainability and collaboration among developers.
Event-DrivenInput events trigger specific callbacks.Facilitates responsive and intuitive XR interactions.

Learning Resources

Unity Input System Documentation(documentation)

The official Unity documentation for the Input System package, covering its core concepts and API.

Unity XR Interaction Toolkit Overview(documentation)

An overview of the XR Interaction Toolkit, explaining its purpose and how it integrates with other Unity systems.

Unity Input System: Getting Started(video)

A beginner-friendly video tutorial demonstrating how to set up and use the Unity Input System.

Unity XR Interaction Toolkit: Input Actions(video)

A video tutorial specifically focusing on how to use Input Actions within the XR Interaction Toolkit.

Unity Blog: Input System for XR(blog)

A blog post from Unity discussing the benefits and implementation of the Input System for XR development.

Unity XR Interaction Toolkit: Input Handling(documentation)

Detailed documentation on how input is handled within the XR Interaction Toolkit, including default actions.

Unity Input System: Action Maps(documentation)

Explains the concept of Action Maps, which are essential for organizing input in the Input System.

Unity Input System: Bindings(documentation)

Learn about how to create bindings to connect physical device inputs to your defined actions.

Unity XR Interaction Toolkit: XR Controller(documentation)

Information on the XR Controller component, which is key to integrating input actions with XR hardware.

Unity Input System: Player Input Component(documentation)

Details on the Player Input component, a convenient way to manage input for players in your game.