【发布时间】:2019-06-18 02:10:26
【问题描述】:
我正在我的 Windows 10 机器上使用虚幻 4.20 和 C++ 制作一个简单的密室逃脱游戏。代码构建/编译得很好,但是当我点击播放时,引擎崩溃了。我尝试重新启动计算机,删除除配置、内容、源文件夹和 .uproject 文件之外的所有文件文件/目录。我尝试删除引擎,但由于管理员权限,它不会让我这样做。我目前正在上“开门”课
这是我的 OpenDoor.h 文件:
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Engine/TriggerVolume.h"
#include "OpenDoor.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UOpenDoor : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UOpenDoor();
protected:
// Called when the game starts
virtual void BeginPlay() override;
private:
void OpenDoor();
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction) override;
public:
UPROPERTY(VisibleAnywhere)
float OpenAngle = 90.0f;
UPROPERTY(EditAnywhere)
ATriggerVolume* PressurePlate;
UPROPERTY(EditAnywhere)
AActor* ActorThatOpens; // Remember pawn inherits from actor
};
这是我的 OpenDoor.cpp 文件:
// Fill out your copyright notice in the Description page of Project Settings.
#include "OpenDoor.h"
// Sets default values for this component's properties
UOpenDoor::UOpenDoor()
{
// Set this component to be initialized when the game starts, and to be
ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
// Called when the game starts
void UOpenDoor::BeginPlay()
{
Super::BeginPlay();
// ...
}
void UOpenDoor::OpenDoor()
{
// Find the owning Actor
AActor* Owner = GetOwner();
}
// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// Poll the Trigger Volume
// If the ActorThatOpens is in the volume
if (PressurePlate->IsOverlappingActor(ActorThatOpens))
{
OpenDoor();
}
}
我是 Unreal 的新手,并且通常将 C++ 作为一门语言进行斗争,所以我想知道它是否与我的代码有关。任何帮助将不胜感激。谢谢!
【问题讨论】:
-
在哪一行崩溃?你试过调试它吗?要知道,如果有东西崩溃了,一个人不会去随意删除东西,他需要调查导致崩溃的原因。在进入大型复杂框架(例如 UE)之前花一些时间学习 C++ 可能是个好主意。
-
PressurePlate在TickComponent中取消引用之前未检查是否为空。 -
进入你保存的文件夹,然后是日志文件夹,看看最后的日志在最底部说了什么。
标签: c++ version-control crash game-engine unreal-engine4