Hi there,
I created a generic ASimpleTriggerVolume
and another more concrete ASimpleBoxTriggerVolume
which overrides some functions. Unfortunately Unreal Editor instantly crashes when trying to start it with this implementation:
SimpleTriggerVolume.h:
UCLASS()
class BEATEMDOWN_API ASimpleTriggerVolume : public AActor
{
GENERATED_BODY()
public:
ASimpleTriggerVolume();
protected:
UPROPERTY(VisibleAnywhere, Category = "Setup")
UShapeComponent* Shape = nullptr;
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
protected:
UFUNCTION()
virtual void OnTriggerOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
UFUNCTION()
virtual void OnTriggerOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
UFUNCTION()
virtual void SetupShapeComponent();
UFUNCTION()
virtual void BindTriggerCallbacksToShape();
};
and SimpleTriggerVolume.cpp:
ASimpleTriggerVolume::ASimpleTriggerVolume()
{
PrimaryActorTick.bCanEverTick = true;
SetupShapeComponent();
BindTriggerCallbacksToShape();
}
void ASimpleTriggerVolume::BeginPlay() { Super::BeginPlay(); }
void ASimpleTriggerVolume::Tick(float DeltaTime) { Super::Tick(DeltaTime); }
void ASimpleTriggerVolume::SetupShapeComponent()
{
auto BoxTrigger = CreateDefaultSubobject<UBoxComponent>(FName("Trigger Shape"));
BoxTrigger->SetBoxExtent(FVector(50.f, 50.f, 50.f));
BoxTrigger->SetGenerateOverlapEvents(true);
Shape = BoxTrigger;
}
void ASimpleTriggerVolume::BindTriggerCallbacksToShape()
{
if (Shape)
{
Shape->OnComponentBeginOverlap.AddDynamic(this, &ASimpleTriggerVolume::OnTriggerOverlapBegin);
Shape->OnComponentEndOverlap.AddDynamic(this, &ASimpleTriggerVolume::OnTriggerOverlapEnd);
}
}
void ASimpleTriggerVolume::OnTriggerOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
UE_LOG(LogTemp, Warning, TEXT("SimpleTriggerVolume::OnTriggerOverlapBegin()"));
}
void ASimpleTriggerVolume::OnTriggerOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
UE_LOG(LogTemp, Warning, TEXT("SimpleTriggerVolume::OnTriggerOverlapEnd()"));
}
With only this script, everyhing works fine. As soon as I inherit from it and override the UFUNCTION SetupShapeComponent Unreal crashes, even before I can hit play.
SimpleBoxTriggerVolume.h:
UCLASS()
class BEATEMDOWN_API ASimpleBoxTriggerVolume : public ASimpleTriggerVolume
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, Category = "Geometry")
FVector TriggerExtent = FVector(50.f, 50.f, 50.f);
ASimpleBoxTriggerVolume();
virtual void BeginPlay() override;
virtual void Tick(float DeltaTime) override;
protected:
///////////////////////////////////////////////////////////////////////////////
//// ASimpleTriggerVolume
virtual void SetupShapeComponent() override;
};
and SimpleBoxTriggerVolume.cpp:
ASimpleBoxTriggerVolume::ASimpleBoxTriggerVolume()
{
PrimaryActorTick.bCanEverTick = true;
RootComponent = CreateDefaultSubobject<USceneComponent>(FName("Root Component"));
SetupShapeComponent();
BindTriggerCallbacksToShape();
}
void ASimpleBoxTriggerVolume::BeginPlay(){Super::BeginPlay();}
void ASimpleBoxTriggerVolume::Tick(float DeltaTime){Super::Tick(DeltaTime);}
void ASimpleBoxTriggerVolume::SetupShapeComponent()
{
auto BoxTrigger = CreateDefaultSubobject<UBoxComponent>(FName("Trigger Shape"));
BoxTrigger->SetBoxExtent(TriggerExtent);
BoxTrigger->SetGenerateOverlapEvents(true);
Shape = BoxTrigger;
}