Skip to main content

Input System

The dialogue input system wraps Unity's Input System to provide consistent input handling across keyboard, mouse, and gamepad.

DialogueInputService is the main entry point. It loads the Dialogue action map from an InputActionAsset and provides methods to check input state and resolve display labels.

Input actions

The dialogue system uses five input actions:

  • Interact -- initiates a conversation with a targeted NPC
  • Advance -- moves to the next beat group or confirms a selected option
  • NavigateUp -- moves the selection highlight up in the options list
  • NavigateDown -- moves the selection highlight down in the options list
  • Cancel -- cancels or exits the conversation

These actions are defined in the DialogueInputActions asset, which ships with the module at Input/Resources/Dialogue/DialogueInputActions.

Device auto-detection

The input service auto-detects whether the player is using keyboard and mouse or a gamepad. It subscribes to InputSystem.onActionChange and updates the current device mode when the player switches input methods.

This affects display labels shown in the prompt and options UI. For example, the interact prompt might show "E" for keyboard or "A" for gamepad.

Configuration

DialogueInputSettingsData provides two settings:

  • DialogueInputModePreference -- controls device detection behaviour:
    • AutoDetect -- switches based on the last input device used (default)
    • KeyboardMouse -- always shows keyboard bindings
    • Gamepad -- always shows gamepad bindings
  • Override InputActionAsset -- an optional custom input actions asset that replaces the default

Mouse interaction

Dialogue options support mouse interaction through DialogueOptionInteractionHandler, a MonoBehaviour attached to each option item. It implements IPointerClickHandler and IPointerEnterHandler:

  • clicking an option selects it immediately
  • hovering over an option highlights it

Mouse events are forwarded to IDialogueInputService through OnOptionClicked and OnOptionHovered events, which the ResponseService subscribes to.

The shared input abstraction

DialogueInputService implements IGameInputProvider, a shared interface from the Shared layer. This abstraction allows other systems to query dialogue input state without depending directly on the dialogue assembly.

Practical advice

The default input actions work with Unity's default input bindings. If your project uses custom input bindings, provide an override InputActionAsset through the input settings rather than modifying the default asset.

Next step

Continue to Localisation.