检查重叠时,虚幻编辑器会崩溃

Unreal Editor Crashes when checking for Overlap

本文关键字:编辑器 崩溃 重叠 检查      更新时间:2023-10-16

虚幻的初学者在这里,我刚刚编写了以下代码,以便触发卷打开门(更改Actors偏航(。如果选定的演员(Actorthotopens(进入它,但是在扮演虚幻编辑器时,请Instatly崩溃。谁能帮忙?我希望它足够清楚我试图实现的目标,如果没有,请询问。

将此代码添加到.h:

private:
     UPROPERTY(VisibleAnywhere)
     float OpenAngle = 90.0f;
     UPROPERTY(EditAnywhere)
     ATriggerVolume* PressurePlate;
     UPROPERTY(EditAnywhere)
     AActor* ActorThatOpens; //Pawn inherits from actor

这给.cpp:

 void UOpenDoor::OpenDoor()
 {
     AActor* Owner = GetOwner();
     FRotator NewRotation = FRotator(0.0f, -160.0f, 0.0f);
     Owner->SetActorRotation(NewRotation);
 }
 // Called every frame
 (line 42) void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
 {
     Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
     // ...
     if (PressurePlate->IsOverlappingActor(ActorThatOpens))
     {
         OpenDoor();
     } 
 }

我确实将压力板设置为triggervolume,并将其添加到演员(门(中。 我得到此错误(UE编辑器崩溃(:

     Fatal error!
 Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000340
 UE4Editor-Engine.dll!0x00000000AB8790A1
 UE4Editor-BuildingGame-9929.dll!UOpenDoor::TickComponent() [d:userslfdocumentsreposunrealcoursebuildinggamesourcebuildinggameopendoor.cpp:42]
 UE4Editor-Engine.dll!0x00000000ABC2C05F
 UE4Editor-Engine.dll!0x00000000ABC51A15
 UE4Editor-Engine.dll!0x00000000AC7DD9DD
 UE4Editor-Engine.dll!0x00000000AC7E385D
 UE4Editor-Core.dll!0x00000000C09ED84D
 UE4Editor-Core.dll!0x00000000C09EDC6D
 UE4Editor-Core.dll!0x00000000C0A0CCEB
 UE4Editor-Engine.dll!0x00000000AC808861
 UE4Editor-Engine.dll!0x00000000AC819532
 UE4Editor-Engine.dll!0x00000000AC147B64
 UE4Editor-Engine.dll!0x00000000AC1501AD
 UE4Editor-Engine.dll!0x00000000ABF05B17
 UE4Editor.exe!0x000000007A96DEE3
 UE4Editor.exe!0x000000007A95EB40
 UE4Editor.exe!0x000000007A95EBBA
 UE4Editor.exe!0x000000007A970A29
 UE4Editor.exe!0x000000007A9722B6
 KERNEL32.DLL!0x00000000E8692774
 ntdll.dll!0x00000000E8F90D61
 ntdll.dll!0x00000000E8F90D61

(遵循本教程:https://www.udemy.com/unrealcourse/learn/v4/v4/t/lecture/4621210?start=15(

sai narayan可能是正确的,您可以在调用游戏逻辑代码之前检查指针有效性。

if ((PressurePlate != nullptr) && (ActorThatOpens != nullptr))
{
    if (PressurePlate->IsOverlappingActor(ActorThatOpens))
    {
        OpenDoor();
    }
}

如果您之前未设置PresurePlateActorThatOpen,则可以防止您的程序崩溃。

请记住,TickComponent功能将在演员拥有您的组件的演员中始于游戏世界。因此,在您将组件成员初始初始初始化之前,可以调用TickComponent

这看起来像是空指针异常。您正在访问尚未正确初始化的指针。

" Actortartopens"在哪里初始化?还有"压力板",请进行双检查以确保这些是有效的指针。

如果重叠被调用/从空对象调用/可能导致崩溃。

不要为此使用tick,这是不必要的开销。UE4是事件驱动的,因此请实现OnoverLapbegin函数以调用您的特定代码。

编辑:首先在蓝图中进行,请确保您的逻辑和执行路径是正确的,然后将其移至代码。这正是蓝图的目的。