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.
Where input is processed
Section titled “Where input is processed”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.
Quick start
Section titled “Quick start”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)endinputs.json
Section titled “inputs.json”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
Section titled “InputActions”FindAction
Section titled “FindAction”InputActions:FindAction(actionName: string): InputAction | nilReturns 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") returnendInputAction
Section titled “InputAction”IsPressed
Section titled “IsPressed”action:IsPressed(): boolReturns 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 endend)OnPerformed
Section titled “OnPerformed”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)Enable and Disable
Section titled “Enable and Disable”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 actionend)
-- LaterInputEnabled = falseCommon mistakes
Section titled “Common mistakes”Name differs from inputs.json
Section titled “Name differs from inputs.json”FindAction() looks up the exact name. Do not treat TogglePanel and togglePanel as the same binding.
Calling methods on nil
Section titled “Calling methods on nil”A missing action returns nil. Check the result before calling a method.
Using input from server.lua
Section titled “Using input from server.lua”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.