Version:

Working with the Input Component

Working with the Input Component

You can create an .inputbindings file for an Input component and specify the input values and events.

Topics

Creating an Input to Event Binding Asset

Follow these steps to create an .inputbindings file.

To create an input to event binding asset

  1. Create an entity.

  2. In the Perspective viewport, select the entity.

  3. In the Entity Inspector, click Add Component, and add the Input component.

  4. In the Entity Inspector, under Input, click the Input Bindings Editor icon [Image NOT FOUND] to open the Asset Editor.
    []

  5. In the Asset Editor, choose File, New, Input Bindings.

  6. Enter a name for the .inputbindings file and click Save.

Creating Input Event Groups

After you create your .inputbindings file, you can add input event groups for different actions.

To add an input event group

  1. In the Asset Editor, for your .inputbindings file, click the + icon.
    []

  2. For Event Name, enter a name for your event, such as Action.
    []

Creating Event Generators

After you create your input event group, you can add event generators to the group. An event generator is a handler that generates the named event. For example, a pressed key, a held mouse button, or a series of actions on a game controller results in the named event.

To add an event generator to your input event group

  1. In the Asset Editor, for your input event group, next to Event Generators, click the + icon.

  2. In the Class to create window, select Input, and click OK.

  3. Specify your changes for the event generator. Each event generator has a set of properties that you can customize.
    Event Generator Properties
    [See the AWS documentation website for more details]
    Example

    The following .inputbindings file specifies a keyboard for the device type and the spacebar for the input name.
    [Input bindings configuration example in the Asset Editor.]

  4. Save your .inputbindings file.

  5. In the Entity Inspector, in the Input component, for Input to event binding, click the browse () icon and select your .inputbindings file.

Mapping Input Events to Gameplay Actions

After you create an .inputbindings file and specify your input events, you can use a Script Canvas graph or Lua script to map the input events to gameplay actions. You can create your graph in a visual scripting environment with the Script Canvas editor or write your own scripts with the Lua Editor (Lua IDE).

Using a Script Canvas Graph for Input

You can create a Script Canvas graph that maps to your input events. For more information, see Creating Gameplay with Script Canvas.

To use a Script Canvas graph for input

  1. In the Perspective viewport, select the entity.

  2. In the Entity Inspector, click Add Component and add the Script Canvas component.

  3. In the Script Canvas component, for Script Canvas Asset, specify a Script Canvas graph like the following.
    Example Script Canvas Graph

    In the following graph, the Input Handler node maps the Event Name Action to the .inputbindings file.
    [Example Script Canvas graph for the Input component.]

Using a Lua Script for Input

You can also create a Lua script that maps to your input events. For more information about Lua, see Writing Lua Scripts.

To add a Lua script for input

  1. In the Perspective viewport, select the entity.

  2. In the Entity Inspector, click Add Component, and add the Lua Script component.

  3. In the Lua Script component, specify a Lua script file like the following.
    Example Lua Script

    The following Lua script maps the Event Name Action to the .inputbindings file.

    local tutorial_input =
    {
    	Properties =
    	{
    	},
    }
    function tutorial_input:OnActivate()
    	self.Inputs = {}
    
    	self.Inputs.OnPressed = function(_, value) 
    		TransformBus.Event.SetLocalScaleZ(self.entityId, 2.0)
    	end
    
    	self.Inputs.OnHeld = function (_, value) 
    		TransformBus.Event.RotateAroundLocalZ(self.entityId, 0.01)
    	end
    
    	self.Inputs.OnReleased = function (_, value) 
    		TransformBus.Event.SetLocalScaleZ(self.entityId, 1.0)
    	end
    
    	self.InputNotificationBus = InputEventNotificationBus.Connect(
    		self.Inputs, InputEventNotificationId("Action")
    	)	
    
    end
    
    function
    tutorial_input:OnDeactivate()
    	self.InputNotificationBus:Disconnect()
    end
    
    return tutorial_input
    

Testing Your Input Events

After you specify the Script Canvas graph or Lua script, you can test your input events.

To test your input events

  1. In the Perspective viewport, select your entity.

  2. In the Entity Inspector, click Add Component, and add the Mesh component.

  3. For Mesh asset, specify a mesh asset file. This gives your entity a shape. For example, you can specify the lumberyard_version\dev\SamplesProject\Objects\Primitives\cube_001.cgf file.

  4. Press Ctrl+G to enter game mode.

  5. Press the keyboard spacebar so that your entity rotates on the local z-axis.
    Example
    [Input bindings configuration example in the Asset Editor.]

  6. To exit gameplay mode, press Esc