Tyl*_*ham 2 c++ unreal-engine4
我目前正在尝试遵循本教程,以便在制作我的第一个游戏时取得良好的开端。除了使用我自己的属性名称之外,我完全遵循了上述教程中的所有内容。我的问题是我的角色类中的这段代码没有被调用:
void AGetOutCharacter::BeginPlay()
{
Super::BeginPlay();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("Using GetOutCharacter"));
}
}
Run Code Online (Sandbox Code Playgroud)
就像在教程中一样,我有一个游戏模式类和一个从该类扩展的蓝图。并且该蓝图类在项目设置中设置为默认游戏模式。该游戏模式使用我的角色类蓝图,它是从我的角色类扩展而来的,作为默认的 pawn 类。同样,这是在项目设置中设置的,就像教程中一样。
我可能只是失去了理智,但我一生都无法弄清楚为什么当我在 PIE 中运行游戏时没有显示调试日志。在我的游戏模式类中,有一个与上面的日志相同的日志,该日志在游戏运行时显示,但不是角色类中的日志。我尝试在游戏模式StartPlay()和角色BeginPlay()函数中放置输出到输出日志控制台的日志语句,同样,游戏模式中的日志语句就像一个魅力,但角色类中的日志语句根本不起作用。我还尝试在字符类中调用该AddOnScreenDebugMessage(...)函数的行放置一个断点,但从未到达该断点。我在游戏模式类中的同一位置放置了一个断点,该断点被击中。Reason 告诉我,这意味着游戏使用我的类的方式有问题,但编辑器显示一切正常。
一个特别有趣且令人困惑的交互是,如下所示,没有设置用于控制玩家移动的映射。因此,当我的游戏模式和角色类别设置为默认值时,正如游戏运行时所预期的那样,角色无法移动。但是,当我将默认 pawn 设置为 stock pawn 类时,这种无法移动的情况仍然存在。只有当我删除游戏模式类作为默认游戏模式时,我才能在运行游戏时重新获得在关卡中移动的能力。这表明正在使用字符类,但它的BeginPlay()函数没有被调用。
任何帮助将不胜感激,因为我已经花了几个小时来解决这个问题。谢谢!
作为参考,以下是游戏模式和角色类别:
游戏模式.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;
};
Run Code Online (Sandbox Code Playgroud)
游戏模式.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"));
}
}
Run Code Online (Sandbox Code Playgroud)
字符.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;
};
Run Code Online (Sandbox Code Playgroud)
人物.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);
}
Run Code Online (Sandbox Code Playgroud)
另外,如果我的项目设置/蓝图出现错误,这里是我的项目的项目设置和参考查看器图: