Input Setup
Last modified: 04 October 2024An Input Setup bundles an Input Mapping Context with their appropriate Input Handlers.
The Input Manager can have default Input Setups available in all situations.
Input Setups can be added or removed using the appropriate functions in the Input Manager:
AddInputSetupData
andRemoveInputSetupData
.New Pawns set to a Player Controller can grant their own Input Sets via
InputSetupProviderInterface
. They are automatically added and removed when the pawn is possessed and unpossessed.
Input Setups are Data Assets used to bundle an Input Mapping Context to all appropriate Input Handlers. These bundles are provided to the Input Manager either as default setups or managed during runtime.
You can categorize Input Setups as:
Default: Always available to the player pawn.
Situational: Added or removed based on specific contexts.
Default Input Setups
Default Input Setups are always active and are assigned within the Input Manager Component’s Default Settings.
The system supports multiple Default Input Setups, providing the flexibility to organize your inputs into as many logical bundles as needed.
The specifics of which default setups to add will vary depending on the project's scope. Smaller games might benefit from having all setups added as default. In contrast, larger games may require more deliberate management of input contexts.
note
Context Priorities
If you have overlapping Setups/Contexts (e.g., Basic Locomotion and Mount Locomotion), consider adjusting their priorities to ensure that the more specific context (like "Mount Locomotion") takes precedence and properly consumes the input.
Situational Input Setups
Situational Input Setups are activated on-demand and are triggered by specific events, allowing for the addition or removal of Input Setups as needed.
Add and Remove Functions
The Input Manager Component provides dedicated functions to add or remove Input Setups whenever necessary. It’s important to ensure that any context you add is properly removed later to avoid unexpected behavior.
note
Input Context Mapping Duplicates
The Input Manager Component does not allow duplicate contexts. Attempting to add a context that has already been processed will generate a warning in the
LogNinjaInput
category.
These functions are available in both Blueprints and C++ and can be used as needed. Here are common usage cases:
Begin or End Play of certain actors that provide additional input options to players.
When the User Interface activates and new inputs are available.
Inputs granted, based on certain conditions that must be met.
#include "Components/NinjaInputManagerComponent.h"
#include "Data/NinjaInputSetupDataAsset.h"
void ANinjaLabsItem::BeginPlay()
{
Super::BeginPlay();
GetOwnerInputManager()->AddInputSetupData(ItemSetupData);
}
void ANinjaLabsItem::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
GetOwnerInputManager()->RemoveInputSetupData(ItemSetupData);
Super::EndPlay(EndPlayReason);
}
Input Setup Provider Interface
Situational Input Setups can also be managed via the Input Setup Provider Interface.
This interface can be implemented by any pawn. When a Player Controller possesses such a pawn, its Input Manager Component checks for this interface and automatically adds the provided setups. The setups are then removed when the pawn is unpossessed.
note
Player Controller Only
The Input Manager Component will look for this interface in Pawns being possessed and unpossessed. This Setup only works when your Input Manager is in the Player Controller!
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Interfaces/InputSetupProviderInterface"
#include "PluginLabsController.generated.h"
class NinjaInputSetupDataAsset;
UCLASS()
class PLUGINLABS_API APluginLabsCharacter : public ACharacter, public IInputSetupProviderInterface
{
GENERATED_BODY()
public:
// -- Begin Input Setup Provider implementation
virtual TArray<UNinjaInputSetupDataAsset*> GetAddedSetups_Implementation() const override;
virtual TArray<UNinjaInputSetupDataAsset*> GetRemovedSetups_Implementation() const override;
// -- End Input Setup Provider implementation
protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Input Setup")
TArray<UNinjaInputSetupDataAsset*> CharacterInputs;
};
#include "GameFramework/APluginLabsCharacter.h"
#include "Data/NinjaInputSetupDataAsset.h"
TArray<UNinjaInputSetupDataAsset*> APluginLabsCharacter::GetAddedSetups_Implementation() const
{
return CharacterInputs;
}
TArray<UNinjaInputSetupDataAsset*> APluginLabsCharacter::GetRemovedSetups_Implementation() const
{
return CharacterInputs;
}
Globally Enable or Disable Inputs
Inputs can be completely disabled, and later on enabled at the Input Manager component level.
This can be useful when doing in-game cutscenes or other similar operations where all inputs should be discarded, without the need to remove/add current Setups.
// Checks if the Input Manager is currently processing inputs.
InputManager->ShouldProcessInputs()
// Enables all input processing.
InputManager->EnableInputProcessing()
// Disables all input processing.
InputManager->DisableInputProcessing()