Skip to content

InputAction

InputActions looks up input actions, while InputAction exposes their state and performed event. The API is client-only. In a Reflex server.lua, the global InputActions object is nil.

inputs.json registers a binding but does not draw a button or hint on the HUD. OnPerformed() only runs a callback; the module must implement every visible result—such as opening a panel, showing a message, or changing an indicator—through UI, ImGui, or another API.

When the module loads, the client adds actions from inputs.json to the shared module input map. The game input system updates each InputAction; IsPressed() then reads its current state, while OnPerformed() invokes subscribers when the action is performed.

This is local user input. It does not become a server command automatically: a Reflex module must explicitly send the required state through Network, and the server must validate it and decide what to do.

Declare a button in the module root’s inputs.json:

{
"Actions": [
{
"Name": "TogglePanel",
"Type": "Button",
"Binding": {
"Path": "<Keyboard>/f8"
}
}
]
}

Look up the same name from main.lua:

local TogglePanel = InputActions:FindAction("TogglePanel")
local PanelVisible = false
if TogglePanel ~= nil then
TogglePanel:OnPerformed(function()
PanelVisible = not PanelVisible
end)
end

Verified button format:

Field Type Description
Actions array The module’s action list.
Name string A unique name passed to FindAction().
Type string Use Button for a regular button action.
Binding.Path string A Unity Input System control path, such as <Keyboard>/f8.

The game rebuilds the module action map after inputs.json changes.

InputActions:FindAction(actionName: string): InputAction | nil

Returns a module action or a built-in game action. For example, UI/Cancel returns the game’s Cancel action. A missing name returns nil.

Always check the result:

local action = InputActions:FindAction("TogglePanel")
if action == nil then
print("TogglePanel action is missing")
return
end
action:IsPressed(): bool

Returns true while the bound control is pressed. Inside OnPerformed() for a physical key press it returned true, then returned false after the key was released.

Scheduler:OnFrame(function()
if action:IsPressed() then
-- Runs while the button is held
end
end)
action:OnPerformed(callback: function)

Registers a callback that runs when the action is performed. The method returns nil.

action:OnPerformed(function()
print("Action performed")
end)
action:Enable()
action:Disable()

Both methods return nil.

Use your own guard for predictable behavior:

local InputEnabled = true
action:OnPerformed(function()
if not InputEnabled then
return
end
-- Handle the action
end)
-- Later
InputEnabled = false

FindAction() looks up the exact name. Do not treat TogglePanel and togglePanel as the same binding.

A missing action returns nil. Check the result before calling a method.

A Reflex server does not receive the client’s keyboard input. Handle the action in main.lua, then send state through Network when the server needs it.