Hello! I am fairly new at programming with C++, just learning through a game dev course.
I was trying to create a Pause menu and bind it to a player component(MyCharacter.cpp). The logic from the pause menu is created in a different class(ShooterPlayerController.cpp) which is currently handling my HUD and other screens.
My current error says the following:
Any help/explanation would be appreciated.
MyCharacter.cpp
#include "MyCharacter.h"
#include "Gun.h"
#include "Components/CapsuleComponent.h"
#include "SimpleShooterGameModeBase.h"
#include "Kismet/GameplayStatics.h"
#include "ShooterPlayerController.h"
// Sets default values
AMyCharacter::AMyCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AMyCharacter::BeginPlay()
{
Super::BeginPlay();
Health = MaxHealth;
GetMesh()->HideBoneByName(TEXT("weapon_r"), EPhysBodyOp::PBO_None);
SpawnGuns();
CanDash = true;
}
// Called every frame
void AMyCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &AMyCharacter::MoveForward);
PlayerInputComponent->BindAxis(TEXT("MoveRight"), this, &AMyCharacter::MoveRight);
PlayerInputComponent->BindAxis(TEXT("LookUp"), this, &APawn::AddControllerPitchInput);
PlayerInputComponent->BindAxis(TEXT("LookUpRate"), this, &AMyCharacter::LookUpRate);
PlayerInputComponent->BindAxis(TEXT("LookRight"), this, &APawn::AddControllerYawInput);
PlayerInputComponent->BindAxis(TEXT("LookRightRate"), this, &AMyCharacter::LookRightRate);
PlayerInputComponent->BindAction(TEXT("WeaponSwitch"), IE_Pressed, this, &AMyCharacter::WeaponChange);
PlayerInputComponent->BindAction(TEXT("Jump"), IE_Pressed, this, &ACharacter::Jump);
PlayerInputComponent->BindAction(TEXT("Shoot"), IE_Released, this, &AMyCharacter::Shoot);
PlayerInputComponent->BindAction(TEXT("WeaponReload"), IE_Released, this, &AMyCharacter::WeaponReload);
PlayerInputComponent->BindAction(TEXT("DashRight"), IE_Pressed, this, &AMyCharacter::DashRight);
PlayerInputComponent->BindAction(TEXT("DashLeft"), IE_Pressed, this, &AMyCharacter::DashLeft);
PlayerInputComponent->BindAction(TEXT("PauseMenu"), IE_Pressed, this, &AShooterPlayerController::PauseMenu);
}
ShooterPlayerController.cpp
#include "ShooterPlayerController.h"
#include "TimerManager.h"
#include "Blueprint/UserWidget.h"
void AShooterPlayerController::BeginPlay()
{
Super::BeginPlay();
HUD = CreateWidget(this, HUDClass);
if(HUD != nullptr)
{
HUD->AddToViewport();
}
}
void AShooterPlayerController::GameHasEnded(class AActor* EndGameFocus, bool bIsWinner)
{
Super::GameHasEnded(EndGameFocus, bIsWinner);
HUD->RemoveFromParent();
if(bIsWinner)
{
UUserWidget* WinScreen = CreateWidget(this, WinScreenClass);
if(WinScreen != nullptr)
{
WinScreen->AddToViewport();
}
}
else
{
UUserWidget* LoseScreen = CreateWidget(this, LoseScreenClass);
if(LoseScreen != nullptr)
{
LoseScreen->AddToViewport();
}
}
GetWorldTimerManager().SetTimer(RestartTimer, this, &APlayerController::RestartLevel, RestartDelay);
}
void AShooterPlayerController::PauseMenu()
{
UUserWidget* PauseScreen = CreateWidget(this, PauseScreenClass);
if (PauseScreen != nullptr)
{
PauseScreen->AddToViewport();
SetPause(true);
SetInputMode(FInputModeUIOnly());
bShowMouseCursor = true;
}
}