Class not being called?

OK, so I created a player controller class and added code to it but nothing happens, I added debug messages and those aren’t being printed either. Can I get help? (BTW I created the class from scratch or blank sheet)



#include "MyProject.h"
#include "MyPlayerController.h"


AMyPlayerController::AMyPlayerController()
{
	PrimaryActorTick.bCanEverTick = false;

}

void AMyPlayerController::BeginPlay(void)
{
	Super::BeginPlay();
	UE_LOG(LogTemp, Warning, TEXT("Logged -1"));
}

void AMyPlayerController::Tick(float deltaTime)
{
	Super::Tick(deltaTime);

}

//void AMyPlayerController::SetupPlayerInputComponent(class UInputComponent *playerInput)
void AMyPlayerController::SetupInputComponent()
{
	//Super::SetupPlayerInputComponent(playerInput);
	Super::SetupInputComponent();

	//playerInput->BindAction("myNewBinding", IE_Released, this, &AMyPlayerController::displayMSG);
	check(InputComponent);
	if (InputComponent != nullptr)
	{
		UE_LOG(LogTemp, Warning, TEXT("Logged 0"));
		InputComponent->BindAction("myBinding", IE_Pressed, this, &AMyPlayerController::displayMSG);
		InputComponent->BindAction("myBinding", IE_Released, this, &AMyPlayerController::displayMSG1);
	}

	//return 0;
}

void AMyPlayerController::displayMSG(void)
{
	UE_LOG(LogTemp, Warning, TEXT("Logged 1"));
	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("Key recognized."));
}

void AMyPlayerController::displayMSG1(void)
{
	UE_LOG(LogTemp, Warning, TEXT("Logged 2"));
	GEngine->AddOnScreenDebugMessage(0, 5.0f, FColor::Red, TEXT("Key released."));
}


Did you assign this to the “player controller class” found in the world settings in the UE4 editor?

No I haven’t, can you guide me? not an editor export, just c++ writer.

I actually added a couple keys still no effect.

You have to set your PC in the game mode. Otherwise UE just doesn’t know that you want to use it.

I’ll strongly suggest giving the introductory YouTube tutorials from UbrealEngine a try since there are quite a few if the gotchas and these videos do a great job of clearing those issues up.

See the right portion of that image.

Thanks guys! I also even got it all done in C++ without editor. my code:



using UnrealBuildTool;

public class MyProject : ModuleRules
{
	public MyProject(TargetInfo Target)
	{
		PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore", "FMODStudio"});

		PrivateDependencyModuleNames.AddRange(new string] {  });

		// Uncomment if you are using Slate UI
		PrivateDependencyModuleNames.AddRange(new string] { "Slate", "SlateCore" });
		
		// Uncomment if you are using online features
		// PrivateDependencyModuleNames.Add("OnlineSubsystem");
		// if ((Target.Platform == UnrealTargetPlatform.Win32) || (Target.Platform == UnrealTargetPlatform.Win64))
		// {
		//		if (UEBuildConfiguration.bCompileSteamOSS == true)
		//		{
		//			DynamicallyLoadedModuleNames.Add("OnlineSubsystemSteam");
		//		}
		// }
	}
}




#include "MyProject.h"
#include "MyPlayerController.h"

AMyPlayerController::AMyPlayerController()
{
	;
}

void AMyPlayerController::PlayerTick(float deltaTime)
{
	Super::PlayerTick(deltaTime);

}

void AMyPlayerController::SetupInputComponent()
{
	Super::SetupInputComponent();

	check(InputComponent);
	UE_LOG(LogTemp, Warning, TEXT("Controller output."));
	//const FInputActionKeyMapping mynewKey(TEXT("myNewBind"), EKeys::NumPadFive, false, false, false, false);
	//InputComponent->AddActionBinding(mynewKey);
	InputComponent->BindKey(EKeys::BackSpace, IE_Pressed, this, &AMyPlayerController::displayMSG1);
	InputComponent->BindKey(EKeys::BackSpace, IE_Released, this, &AMyPlayerController::displayMSG2);
}

void AMyPlayerController::displayMSG1(void)
{
	UE_LOG(LogTemp, Warning, TEXT("debug msg1."));
	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("Key Recognized."));
}

void AMyPlayerController::displayMSG2(void)
{
	UE_LOG(LogTemp, Warning, TEXT("debug msg2."));
	GEngine->AddOnScreenDebugMessage(0, 5.0f, FColor::Yellow, TEXT("Key Released."));
}




#pragma once

#include "GameFramework/PlayerController.h"
#include "MyPlayerController.generated.h"

/**
 * 
 */
UCLASS()
class MYPROJECT_API AMyPlayerController : public APlayerController
{
	GENERATED_BODY()
public:
	AMyPlayerController();
protected:
	virtual void PlayerTick(float deltaTime) override;
	virtual void SetupInputComponent() override;
	void displayMSG1(void);
	void displayMSG2(void);
};




#include "MyProject.h"
#include "MyProjectGameMode.h"
#include "MyPlayerController.h"



AMyProjectGameMode::AMyProjectGameMode()
{
	PlayerControllerClass = AMyPlayerController::StaticClass();
}