Input Reactor

Base and concrete reactor components — convert unit input state into pressed/held/released events or axis changes for movement and actions.

Input reactor components sit on the unit entity and listen to InputDataNotificationBus. They are the unit-side response layer that turns stored input state into game actions — movement vectors, ability triggers, UI navigation, etc.

For usage guides and setup examples, see The Basics: GS_Unit.

Input Reactor component in the O3DE Inspector

 

Contents


How It Works

Each reactor declares which event names it cares about (inputReactEvents). When InputDataNotificationBus::InputStateChanged fires, the reactor compares the incoming stateName against its list. If it matches, it compares the new value against the previously stored value and calls the correct virtual method:

  • 0 → non-zeroHandlePressed
  • non-zero → non-zeroHandleHeld
  • non-zero → 0HandleReleased
  • any changeHandleAxisChanged (axis variant only)

Reactors store lastInputValues per event name to track zero-crossings between frames.


Base Classes

GS_InputReactorComponent

Base class for discrete button/key input. Extend this to react to named input events with press, hold, and release semantics.

Virtual methods to override:

MethodParametersDescription
HandlePressedAZStd::string stateNameCalled when the event value crosses from 0 to non-zero.
HandleHeldAZStd::string stateNameCalled each frame while the event value remains non-zero.
HandleReleasedAZStd::string stateNameCalled when the event value crosses from non-zero to 0.

Fields:

FieldDescription
inputReactEventsList of event name strings this reactor listens for
lastInputValuesMap of {eventName → float} tracking previous values for zero-crossing detection

GS_InputAxisReactorComponent

Base class for analogue axis input. Extend this for joystick, trigger, or any continuous value that should not use pressed/held/released semantics.

Virtual methods to override:

MethodParametersDescription
HandleAxisChangedAZStd::string stateName, float valueCalled whenever the axis value changes.

Concrete Reactors

KeyboardMovement_InputReactorComponent

Converts four discrete directional key events into a 2D movement axis. Maps moveUp/moveDown/moveLeft/moveRight to +1/-1 contributions on the X and Y axes. On any key press or release, recomputes the combined axis and calls MoverContextRequestBus::SetMoveInputAxis("x"/"y", value) on the unit.

FieldDescription
moveUpEventEvent name for the forward/up key
moveDownEventEvent name for the back/down key
moveLeftEventEvent name for the left key
moveRightEventEvent name for the right key

Internal accumulation fields:

FieldDescription
xAxisPositive / xAxisNegativeAccumulated +X and -X contributions
yAxisPositive / yAxisNegativeAccumulated +Y and -Y contributions

JoyAxisMovement_AxisReactorComponent

Directly maps two joystick axis event names to the Mover Context X and Y movement axes. Calls MoverContextRequestBus::SetMoveInputAxis("x"/"y", value) directly from HandleAxisChanged.

FieldDescription
xAxisNameInput event name for the horizontal axis
yAxisNameInput event name for the vertical axis

API Reference

Reactors themselves do not expose a request bus. They consume InputDataNotificationBus and produce calls to MoverContextRequestBus or other action buses.

InputDataNotificationBus (consumed)

EventDescription
InputStateChanged(stateName, value)Triggers zero-crossing comparison and calls HandlePressed/HandleHeld/HandleReleased/HandleAxisChanged.
ClearInput()Resets all lastInputValues to zero, triggering releases for any held inputs.

MoverContextRequestBus (produced by movement reactors)

CallDescription
SetMoveInputAxis("x", value)Sets the horizontal axis input (−1 to 1) on the unit’s MoverContext.
SetMoveInputAxis("y", value)Sets the vertical axis input (−1 to 1) on the unit’s MoverContext.

Extension Guide

Use the InputReactor ClassWizard template to generate a new input reactor with boilerplate already in place — see GS_Unit Templates.

Create custom reactor components by extending GS_InputReactorComponent or GS_InputAxisReactorComponent.

#pragma once
#include <GS_Unit/InputData/GS_InputReactorComponent.h>

namespace MyProject
{
    class AbilityInputReactor : public GS_Unit::GS_InputReactorComponent
    {
    public:
        AZ_COMPONENT_DECL(AbilityInputReactor);
        static void Reflect(AZ::ReflectContext* context);

    protected:
        void HandlePressed(const AZStd::string& stateName) override;
        void HandleReleased(const AZStd::string& stateName) override;
    };
}

In Reflect(), add the event names you want to listen to:

// In your component's activation or reflection, populate inputReactEvents:
inputReactEvents.push_back("ability_primary");
inputReactEvents.push_back("ability_secondary");

See Also


Get GS_Unit

GS_Unit — Explore this gem on the product page and add it to your project.