diff --git a/Code/Framework/AzFramework/AzFramework/Input/Channels/InputChannel.cpp b/Code/Framework/AzFramework/AzFramework/Input/Channels/InputChannel.cpp index c274bbf491..81dec1cac7 100644 --- a/Code/Framework/AzFramework/AzFramework/Input/Channels/InputChannel.cpp +++ b/Code/Framework/AzFramework/AzFramework/Input/Channels/InputChannel.cpp @@ -327,7 +327,7 @@ namespace AzFramework break; } - if (m_state != State::Idle) + if (m_state != State::Idle && m_shouldDispatchEvents) { bool hasBeenConsumed = false; InputChannelNotificationBus::Broadcast(&InputChannelNotifications::OnInputChannelEvent, @@ -350,4 +350,22 @@ namespace AzFramework // Directly return the channel to the 'Idle' state m_state = State::Idle; } + + //////////////////////////////////////////////////////////////////////////////////////////////// + void InputChannel::SetUpdateEventsEnabled(bool enabled) + { + if (m_shouldDispatchEvents != enabled) + { + m_shouldDispatchEvents = enabled; + const InputChannelRequests::BusIdType busId(m_inputChannelId, m_inputDevice.GetInputDeviceId().GetIndex()); + if (enabled) + { + InputChannelRequestBus::Handler::BusConnect(busId); + } + else + { + InputChannelRequestBus::Handler::BusDisconnect(busId); + } + } + } } // namespace AzFramework diff --git a/Code/Framework/AzFramework/AzFramework/Input/Channels/InputChannel.h b/Code/Framework/AzFramework/AzFramework/Input/Channels/InputChannel.h index fc5dc2a7b2..8be719e979 100644 --- a/Code/Framework/AzFramework/AzFramework/Input/Channels/InputChannel.h +++ b/Code/Framework/AzFramework/AzFramework/Input/Channels/InputChannel.h @@ -218,12 +218,23 @@ namespace AzFramework //! \ref AzFramework::InputChannelRequests::ResetState void ResetState() override; + //////////////////////////////////////////////////////////////////////////////////////////// + //! Sets whether or not the channel shall broadcast to the InputChannelNotificationBus when + //! its internal state is updated. + //! This can be disabled to allow for testing or synthetic events that aren't part of the + //! input system. + void SetUpdateEventsEnabled(bool enabled); + private: //////////////////////////////////////////////////////////////////////////////////////////// // Variables const InputChannelId m_inputChannelId; //!< Id of the input channel const InputDevice& m_inputDevice; //!< Input device that owns the input channel State m_state; //!< Current state of the input channel + + //! If true, &InputChannelNotifications::OnInputChannelEvent will be fired when UpdateState + //! is called. + bool m_shouldDispatchEvents = true; }; ////////////////////////////////////////////////////////////////////////////////////////////////