Hi!
Reading this post, that I asked, Where to process an Input Action
I have implemented the following in a PlayerController:
Header.
#pragma once
"CoreMinimal.h"
"GameFramework/PlayerController.h"
"SNPlayerController.generated.h"
struct FInputActionValue;
class UInputAction;
class UInputMappingContext;
/**
*
*/
UCLASS()
class MYGAME_API ASNPlayerController : public APlayerController
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, Category = "Input")
UInputMappingContext* DefaultInputMapping;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
UInputAction* ShootAction;
protected:
virtual void BeginPlay() override;
virtual void SetupInputComponent() override;
};
CPP.
"SNPlayerController.h"
"EnhancedInputComponent.h"
"EnhancedInputSubsystems.h"
"SNPlayerCharacter.h"
void ASNPlayerController::BeginPlay()
{
Super::BeginPlay();
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
{
Subsystem->ClearAllMappings();
Subsystem->AddMappingContext(DefaultInputMapping, 0);
}
}
void ASNPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
UEnhancedInputComponent* Input = Cast<UEnhancedInputComponent>(InputComponent);
ASNPlayerCharacter* PlayerCharacter = Cast<ASNPlayerCharacter>(GetPawn());
Input->BindAction(ShootAction, ETriggerEvent::Started, PlayerCharacter, &ASNPlayerCharacter::Shoot);
}
I’m calling a method from the Player’s Character class from the Player Controller.
Is this the idea behind “decoding the player’s intent” should be in the player controller, and “implementing the decoded intent” should be in the character / pawn?
Maybe, I can create a shoot method in the Player Controller class, and call the ASNPlayerCharacter::Shoot on it.
Or maybe, I can bind the actions in the PlayerCharacter class.
Or I’m getting totally mixed up.
Thanks!