【问题标题】:Unreal Engine 4.20 crashes when I try to play?当我尝试玩时,虚幻引擎 4.20 崩溃?
【发布时间】: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++ 可能是个好主意。
  • PressurePlateTickComponent 中取消引用之前未检查是否为空。
  • 进入你保存的文件夹,然后是日志文件夹,看看最后的日志在最底部说了什么。

标签: c++ version-control crash game-engine unreal-engine4


【解决方案1】:

你必须检查的空指针

压力板

ActorThatOpens

在使用它们之前保护所有指针也是一个很好的做法,这样您就不会因为引用空指针而崩溃。即便如此,您的代码应该可以工作,可能您忘记在编辑器上设置引用。

我为你解决了这个问题:

void UOpenDoor::OpenDoor()
{
  // Find the owning Actor
  if(!GetOwner()) return;
  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 == nullptr) //Checking for the PressurePlate
   {
      UE_LOG(LogTemp, Warning, TEXT("Missing PressurePlate");
      return;
   }
   if(ActorThatOpens == nullptr) // Checking for the Door
   {
   UE_LOG(LogTemp, Warning, TEXT("Missing ActorThatOpens");
   return;
   }
   if (PressurePlate->IsOverlappingActor(ActorThatOpens))
    {
     OpenDoor();
    }
} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-24
    • 2017-09-20
    • 2017-09-10
    • 1970-01-01
    • 2020-06-02
    • 1970-01-01
    • 2020-02-17
    • 2020-03-24
    相关资源
    最近更新 更多