当我尝试玩时,虚幻引擎4.20崩溃了吗?

问题描述 投票:0回答:1

我在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 ++作为一般语言方面很挣扎,所以我想知道我的代码是否存在问题。任何帮助将不胜感激。谢谢!

c++ version-control crash game-engine unreal-engine4
1个回答
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();
    }
} 
© www.soinside.com 2019 - 2024. All rights reserved.