The default IMCs used by derived BP_ODK_PlayerCharacterBase
assets can be configured by overriding the GetInputMappingContexts
function. Simply return a list of IMCs with a configured priority. You can call the base class function to include the IMCs used by the base if you like.
You can derived your widgets from WBP_ODK_Widget
. The InputMappingContexts
property WBP_ODK_Widget
can be used to configure which IMCs should be active when the widget is on screen. This will use the BPC_ODK_InputComponent
to push a new IMC state onto the stack when the widget is displayed on screen. When the widget is closed, the state will be removed enabling whatever IMCs where active before the widget was opened.
BPC_ODK_InputComponent
is the main manager of input in the ODK. This component lives on the BP_ODK_PlayerControllerBase
asset.
Registering IMCs
BPC_ODK_InputComponent
should be configured on your player controller by adding all Input Mapping Context relevent to your game into the AllInputMappingContexts
property. This will ensure all your IMCs are registered at the start of the game.
Enabling and disabling IMCs
BPC_ODK_InputComponent
can be used to enable and disable sets of IMCs. BPC_ODK_InputComponent
uses a stack of IMC states that can be added and removed from. PushInputMappingContextState
can be used to disable all active IMCs and then activate a given set of IMCs. PushInputMappingContextState
returns an ID that can be used to remove this state from the stack when appropriate. RemoveInputMappingState
can be can be used to remove a state from the stack. When a state is removed, if it is the currently active state, all IMCs associated with the stack will be disabled and the IMCs associated with the next state in the stack will be enabled.
Getting the last input type
BPC_ODK_InputComponent
can be used to get the last input state (Gamepad/Keyboard) by calling GetLastInputType
or hooking into the event OnInputTypeUpdated
.
GetInputMappingContexts
Adding a new configurable input action
To enable configurable keybindings for an input action, you should configure the following on the InputAction asset.
You first may want to add the IM_MappingGroup
modifier. This defines what context the input action can be used. This is used to automatically reset deuplicate input action keys that are in the same mapping group. As an example, the jump and move forward input action have been added to the same mapping group so that if the user can not add the same key for both.
You then will need to add PlayerMappableKeySettings to the input action's user settings. The following should be configured: Name - just the name of your input action asset. Display Name - The text to be shown to the player in UI. Display Category - The category your input action will be put under in the keybindings UI.
Lastly, you will need to configure you input action inside whatever IMCs it is added to. You should probably add keys for both keyboard and the gamepad. The following should be configured: Name - This should be the name of the input action asset appeneded with either "Keyboard" or "Gamepad" respectively. Additionally, if your input action needs to be added to multiple IMCs, due to the fact that the "Name" property must be unique accross the project, you can append a different number to the end of the name in each IMC.