Character :: BeginPlay()未被调用

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"));
    }

}

就像在教程中一样,我有一个游戏模式类和一个从该类扩展的蓝图。该蓝图类在项目设置中被设置为默认游戏模式。该游戏模式使用从角色类扩展的角色类蓝图作为默认的典当类。同样,这是在项目设置中设置的,就像在教程中一样。

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.

由于我已经解决了几个小时的问题,对您的帮助将不胜感激。谢谢!

作为参考,以下是游戏模式和角色类:

游戏模式

// 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"));
    }
}

字符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;

};

字符.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);

}

同样,如果我对项目设置/蓝图犯了错误,这是项目的项目设置和参考查看器图:

Project Settings

RefernceViewer Diagram

评论
  • 别掏心
    别掏心 回复

    与朋友交谈后,我发现了问题的原因!

    In the game mode class, the StartPlay() function I am overriding isn't calling Super::StartPlay()

    添加,解决问题。