Input Component EBus Interface

Input subcomponents are objects that have the same lifetime as components and must override Activate and Deactivate.

//////////////////////////////////////////////////////////////////////////
// InputSubComponent
void Activate(const AZ::InputEventNotificationId& channelId) override;
void Deactivate(const AZ::InputEventNotificationId& channelId) override;

You can use the GameplayNotificationBus to work with the InputSubComponent. You can find example Lua scripts and code in the Gems\StartingPointInput\Assets\Scripts\Input directory.

Input Event Notification Bus

Use the following notification functions with the event notification bus interface to communicate with other components of your game.

For more information about using the event bus (EBus) interface, see Working with the Event Bus (EBus) system .


Request NameDescriptionParametersReturnScriptable
OnPressedEvent sent when an input surpasses the threshold.FloatNoneYes
OnHeldEvent sent when an input continues to surpass the threshold.FloatNoneYes
OnReleasedEvent sent when an input no longer surpasses the threshold.FloatNoneYes

Example

local held =
{
    Properties =
    {
        IncomingInputEventName = "",
        OutgoingGameplayEventName = "",
    },
}

function held:OnActivate()
    local inputBusId = InputEventNotificationId(self.Properties.IncomingInputEventName)
    self.inputBus = InputEventNotificationBus.Connect(self, inputBusId)
end


function held:OnHeld(floatValue)
    GameplayNotificationBus.Event.OnEventUpdating(GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName), floatValue)
end

function held:OnReleased(floatValue)
    GameplayNotificationBus.Event.OnEventEnd(GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName), floatValue)
end

function held:OnDeactivate()
    self.inputBus:Disconnect()
end

return held

Input Request Bus

Use the following functions with the input request bus interface to communicate with other components of your game.

For more information about using the event bus (EBus) interface, see Working with the Event Bus (EBus) system .


Request NameDescriptionParametersReturnScriptable
PushContextPushes a new context onto the stack, which becomes the active context.StringNoneYes
PopContextRemoves the top context from the input context stack.NoneNoneYes
PopAllContextsClears the context stack, and the active context becomes the empty string: ""NoneEmpty stringYes
GetCurrentContextReturns the context at the top of the stack. If the stack is empty, returns: ""NoneStringYes

Example Input Contexts You can use the Input contexts parameter to specify what context asset binding is available. For example, you can switch contexts so that when a character is under water, the input events are different than when the character is on the ground. For example, for the Input component, you can specify Input contexts, such as an empty string, "under water", and "run". When you add a Lua component to the entity, you can specify the different Input contexts, "under water", and "run" in your Lua script. This means that when your Lua script runs, the Lua script tells the Input component which context to use.

local foo
{
    Properties =
    {
        Context {default = "", description = "A context to push onto the input stack."},
    }
}

function foo:OnActivate()
    -- by default the context is blank ""
    InputRequestBus.Broadcast.PushContext(self.Properties.Context) -- context stack is now 1)user defined property
    InputRequestBus.Broadcast.PushContext("under water") -- context stack is now 1)user defined property, 2) "under water"
    Debug.Log(InputRequestBus.Broadcast.GetCurrentContext()) -- prints "under water"
    InputRequestBus.Broadcast.PushContext("run") -- context stack is now 1)use defined property, 2) "under water", 3) "run"
    InputRequestBus.Broadcast.PopContext() -- context stack is now 1)user defined property, 2) "under water"
    InputRequestBus.Broadcast.PopAllContexts() context stack is now empty
end

return foo

Copyright © 2022 Open 3D Engine Contributors

Documentation Distributed under CC BY 4.0.
For our trademark, privacy and antitrust policies, code of conduct, and terms of use, please click the applicable link below or see https://www.lfprojects.org.


The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see our Trademark Policy page.