Table of Contents
This input reader is a system that melds seamlessly with the custom event system installed on the project, whilst it could use C# event actions as well I thought it best to integrate it with the Custom Event System.
For this demonstration we’re going to, step by step, add a sprint button and give it functionality.


Open the InputReader script and you should see an error on the GameInput.IGameplayActions, GameInput.IUIActions or another GameInput Interface declaration saying that the interface is not implemented, this is because it needs a function for every InputAction that exists. You can either click the quickactions lightbulb icon and select implement interface.

or you could manually create the new function using the name you gave it in the action map for example in the code below:
public void OnSprint(InputAction.CallbackContext context)
{
}
Back in Unity, go to the GameEvents/InputEvents folder and create an new GameEvent, for sprint we will call it Input_OnSprint. in the InputReader script, create a new public GameEvent variable for your new input action.
public GameEvent SprintEvent;
Next you want to drag the Input_OnSprint GameEvent into the InputReader object.


Finally we need some data to send, for the sprint we’ll be sending a bool based on whether the Shift button is being pressed so we need to open the InputReader script and in the function:
**OnSprint(InputAction.CallbackContext context)**
The context is used to get whatever information you could want from the input and we’ll use it to check if the button is pressed by checking for context.performed and context.cancelled like in the code below:
public void OnSprint(InputAction.CallbackContext context)
{
if (context.performed)
SprintEvent.Raise(true);
else if (context.canceled)
SprintEvent.Raise(false);
}
In this section you learn how to hook up the input event to a script that will receive the input signal.
Open the script that you’d like to receive the input, for example the player script, and add a new function following the below format:
public void OnInputRecieve(Component sender, object data)
{
}
Then fill in the desired code you’ll need, you can convert data into your desired data type by prefixing it with the data type, for example getting a Vector2 for move input as so:
// You can either directly convert the data object
moveInput = (Vector2)data;
// or you could check for the data type using an if statement and assign a variable
if (data is Vector2 vectorData)
moveInput = vectorData;
Once you have the logic that will run with your input data you need to enable the script to receive said input. In Unity, click on the object with the script attached and add a GemeEventListener Component.

In the GameEventListener, assign the Input Event into the Game Event slot,

Then click the + icon in the Response area and assign the script to the Object, cluck the dropdown arrow and go to the desired script

There, another dropdown with all the possible functions will show up, select the new function you made, in the Dynamic section, as this allows the event to pass data to the function, and your event will be correctly hooked up to the InputReader, and the logic for your new InputAction is fully set up.
