I am currently trying to follow this tutorial, to get a good start on making my first game. I have followed everything in the aforementioned tutorial exactly, save for using my own property names. My issue is that this code in my character class isn't being called:
void AGetOutCharacter::BeginPlay()
{
Super::BeginPlay();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("Using GetOutCharacter"));
}
}
Just like in the tutorial, I have a game mode class and a blueprint extended from that class. And that blueprint class is set as the default game mode in project settings. That game mode is using my character class blueprint, that is extended from my character class, as the default pawn class. Again, this is set in project settings, just like in the tutorial.
I may just be losing my mind, but I cannot for the life of me figure out why the debug log isn't displaying when I run the game in PIE. There is an identical log to the one above in my game mode class that does display when the game runs, but not the one on the character class. I have tried putting log statements that output to the output log console in both the game mode StartPlay() and character BeginPlay() functions, and again, the one in the game mode works like a charm but the one in the character class does not work at all. I have also tried placing a breakpoint at the line that the AddOnScreenDebugMessage(...) function is called in the character class, and that breakpoint is never reached. I placed a breakpoint in the game mode class in the same spot, and that one gets hit. Reason is telling me that this means there something wrong with how the game is using my classes, but the editor shows everything as okay.
One particularly interesting, and majorly confusing, interaction is that as seen below, there is no mappings set up for controlling player movement. So when my game mode and character classes are set as the defaults, as expected when the game runs, the character cannot move. However, when I set the default pawn to the stock pawn class, this inability to move persists. Only when I remove my game mode class as the default game mode do I regain the ability to move around my level when I run the game. This suggests that the character class is being used, yet it's BeginPlay() function is not being called.
Any help would be hugely appreciated as I have been reworking this problem for hours. Thanks!
For reference, here are the game mode and character classes:
GameMode.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GetOutGameModeBase.h"
#include "GetOutGameMode.generated.h"
/**
*
*/
UCLASS()
class GETOUT_API AGetOutGameMode : public AGetOutGameModeBase
{
GENERATED_BODY()
public:
virtual void StartPlay() override;
};
GameMode.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "GetOutGameMode.h"
void AGetOutGameMode::StartPlay()
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("Using GetOutGameMode"));
}
}
Character.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "GetOutCharacter.generated.h"
UCLASS()
class GETOUT_API AGetOutCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AGetOutCharacter();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};
Character.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "GetOutCharacter.h"
// Sets default values
AGetOutCharacter::AGetOutCharacter()
{
// 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 AGetOutCharacter::BeginPlay()
{
Super::BeginPlay();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("Using GetOutCharacter"));
}
}
// Called every frame
void AGetOutCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AGetOutCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
Also in case I made a mistake with my project settings/blueprints, here are the project settings and reference viewer diagrams for my project: