首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >字符:BeginPlay()未被调用

字符:BeginPlay()未被调用
EN

Stack Overflow用户
提问于 2020-05-23 23:08:02
回答 1查看 2.7K关注 0票数 2

我目前正试图遵循这个教程,以获得一个良好的开始,使我的第一场比赛。除了使用我自己的属性名称之外,我已经完全遵循了上述教程中的所有内容。我的问题是,我的字符类中的代码没有被调用:

代码语言:javascript
运行
复制
void AGetOutCharacter::BeginPlay()
{
    Super::BeginPlay();

    if (GEngine)
    {
        GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("Using GetOutCharacter"));
    }

}

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

我可能只是失去了理智,但我不知道为什么调试日志没有显示当我运行游戏饼。在我的游戏模式类中,有一个与上面的日志相同的日志,它在游戏运行时会显示,而不是在字符类上显示。我尝试将输出到输出日志控制台的日志语句放在游戏模式StartPlay()和字符BeginPlay()函数中,而游戏模式中的日志语句工作起来很有魅力,但字符类中的日志语句根本不起作用。我还尝试在字符类中调用AddOnScreenDebugMessage(...)函数的行中放置一个断点,但从未到达该断点。我在游戏模式类中放置了一个断点,然后那个点就被击中了。原因是告诉我,这意味着游戏如何使用我的类有问题,但编辑器显示一切都好。

一个特别有趣,也是最令人困惑的交互是,如下图所示,没有为控制玩家的移动建立映射。因此,当我的游戏模式和字符类被设置为默认值时,正如游戏运行时所期望的那样,角色不能移动。但是,当我将默认典当设置为股票典当类时,这种无法移动的情况仍然存在。只有当我将游戏模式类作为默认游戏模式移除时,我才能在运行游戏时恢复在我的水平上移动的能力。这表明使用的是字符类,但没有调用它的BeginPlay()函数。

任何帮助都将是非常感谢的,因为我已经重新解决这个问题数小时了。谢谢!

以下是游戏模式和字符类,供参考:

GameMode.h

代码语言:javascript
运行
复制
// 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

代码语言:javascript
运行
复制
// 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

代码语言:javascript
运行
复制
// 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

代码语言:javascript
运行
复制
// 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);

}

此外,如果我在项目设置/蓝图中出错,以下是我的项目的项目设置和参考查看器图:

项目设置

RefernceViewer图

EN

回答 1

Stack Overflow用户

发布于 2020-05-23 23:38:35

和朋友谈完之后,我发现了问题的原因!

在游戏模式类中,我要重写的StartPlay()函数没有调用Super::StartPlay()

加上这一点,就解决了问题。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61979712

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档