Download

Custom PlayerController not firing SetupInputComponent

Hi new to UE4 switch from Unity3D after more then 9 years, trying to get my head around GamePlay flow. GameMode, PlayerController, Character more precise.

I made a custom GameMode which uses a Custom PlayerController and a Custom Character.
Now i’m trying to Bind spawning the character in the PlayerController’s SetupInputComponent like this (also set the action in input settings):


void AMTCPlayerController::SetupInputComponent()
{
    UE_LOG(LogTemp, Warning, TEXT("Setting Input"));
    Super::SetupInputComponent();
    check(InputComponent);

    InputComponent->BindAction("SpawnMTCPlayerController", IE_Pressed, this, &AMTCPlayerController::SpawnMTCPlayerController);
}

Which should Execute:


void AMTCPlayerController::SpawnMTCPlayerController()
{
    UE_LOG(LogTemp, Warning, TEXT("Call Spawn"));

    AMTCGameModeBase* GM = Cast<AMTCGameModeBase>(GetWorld()->GetAuthGameMode());
    GM->SpawnCharacter();

}

and finally:


void AMTCGameModeBase::SpawnCharacter()
{
    UE_LOG(LogTemp, Warning, TEXT("Spawn"));
    AMTCPlayerController* PC = Cast<AMTCPlayerController>(PlayerControllerClass);
    APawn* PossedPawn = PC->GetPawn();
    if (PossedPawn)
        PossedPawn->Destroy();
    AMTCCharacter* Fighter = GetWorld()->SpawnActor<AMTCCharacter>(AMTCCharacter::StaticClass(), FVector(0.0f), FRotator(0.0f));
    PC->Possess(Fighter);
}

Not sure if this is correct, just trying to control the spawning of a character for later when the player chooses his/her character in a character select menu.
Problem is none of the LOG’s get printed? not even the one in SetupInputComponent?
Assuming SetupInputComponent get called automatically, anything wrong in the code?
Also yes i said the Custom GameMode in project setting (With custom PlayerController and custom Character) and same in World Settings.
Which automatically spawns the custom Character, but no Inputs work.

Any help is greatly appreciated.

Have you defined the input action “SpawnMTCPlayerController” in the project settings?

Could you paste your constructor/Begin play functions etc? I had a similar problem once and forgot to call one of the overriden functions

hey thanks for answering.
I found the problem: I was also overriding :


void AMTCPlayerController::InitInputSystem()
{
}

Seem Player controller calls SetupInputComponent in there, so calling Super in there solved it:



void AMTCPlayerController::InitInputSystem()
{
    Super::InitInputSystem();
    UE_LOG(LogTemp, Warning, TEXT("Init Input"));
}