Working on a CRPG/RTS situation where I figure it’d behoove the project to take the controller out of the characters. Of course my genius idea was to try this:
#include "GameController.h"
#include "EnhancedInputSubsystems.h"
#include "EnhancedInputComponent.h"
AGameController::AGameController() {
}
void AGameController::BeginPlay() {
Super::BeginPlay();
SetShowMouseCursor(true);
if (this)
{
UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(this->GetLocalPlayer());
if (Subsystem)
{
Subsystem->AddMappingContext(CRPGMapContext, 0);
}
}
}
void AGameController::Tick(float DeltaTime) {
Super::Tick(DeltaTime);
UE_LOG(LogTemp, Warning, TEXT("ITS ALIVE"));
}
void AGameController::SetupInputComponent()
{
Super::SetupInputComponent();
if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(this))
{
EnhancedInputComponent->BindAction(LCAction, ETriggerEvent::Completed, this, &AGameController::LeftClick);
}
}
Of course it doesn’t work, crashes Unreal on play. Problem is, I can’t for the life of me figure out how to set this up properly. I’ve tried a few different things but am just completely lost. Could I get some guidance on how this needs to be handled properly please?