UE5 EnhancedInputSystem Documentation not good?

Hey guys, I am a Unity 3D developer and new to UE5.3. I am trying to make a horror game, but the issue is that I am trying to use the enhanced input system in C++ and can’t find how to implement it properly in code. As i said, I am new and dont understand the documents, Can i get help?

Please do not RTFM me.

I used some youtube tutorials for the Enhanced Input in C++:

But here I let you some important code for you to take a look:
In the .h of the character I add this include and I create this variables:

#include "InputActionValue.h"

/* ----- Mapping Contexts ----- */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input)
class UInputMappingContext* _mainMappingContext;
/* ------------------------------ */

/* ----- Input Actions ----- */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
class UInputAction* _moveAction;
/* ------------------------- */

// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* playerInputComponent) override;

// The functions you bind have the FInputActionValue& value to get the value that the Input Action passes to the function when it's called (the boolean value, the Axis, etc)
void Function(const FInputActionValue& value);

And in the .cpp I add this code:

#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"

// Adding mapping context
void ACharacter::BeginPlay()
{
	Super::BeginPlay();

        // Get the Player Controller in the BeginPlay of the Character, when the game starts.
	_playerController = UGameplayStatics::GetPlayerController(this, 0);

        // Then here it adds an Input Mapping Context (if you don't know the main assets of the Enhanced Input I recommend you to read the UE5 docummentation and also take a look in some forums/tutorials but the basic is the Input Actions and the Input Mapping Context) getting first the UEnhancedInputLocalPlayerSubsystem and adding the _mainMappingContext that it's an EditAnywhere UPROPERTY of an UInputMappingContext* (the Input Mapping Context you wanna add)
	if (_playerController) {
		if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(_playerController->GetLocalPlayer()))
			Subsystem->AddMappingContext(_mainMappingContext, 0);
	}
}


// Binding functions to Input Actions
void ACharacter::SetupPlayerInputComponent(UInputComponent *playerInputComponent)
{
	Super::SetupPlayerInputComponent(playerInputComponent);

	if (UEnhancedInputComponent *EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(playerInputComponent)) {
		// Binding of the action here! The _moveAction is the Input Action and then the ETriggerEvent you can select whatever you need, then the this is if you wanna bind it in the same object or in another (make sure the other object it's not nullptr when the binding happens or when the user press the key) and then the function you want to bind
		EnhancedInputComponent->BindAction(_moveAction, ETriggerEvent::Triggered, this, &ACharacter::Function);

Hope it clears some stuff on how to start working with the Enhanced Input System in UE5 C++. If you have some questions feel free to ask or DM me :slight_smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.