繁体   English   中英

尝试播放时,虚幻引擎4.20崩溃?

[英]Unreal Engine 4.20 crashes when I try to play?

我正在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 ++作为一种语言而苦苦挣扎,所以我想知道这是否与我的代码有关。 任何帮助将不胜感激。 谢谢!

您必须检查的空指针

PressurePlate

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM