So i have a very simple script, its an AActor with a UStaticMeshComponent. I have it set up in such a way that it should call a function once 10 seconds elapse that would destroy the actor.
When i compile and launch the project from the unreal project browser, everything works perfectly fine. However, when i launch the engine from inside the editor (as in clicking local windows debugger) it throws an error for no apparent reason.
.cpp
#include "FirewallV2.h"
#include "UObject/ConstructorHelpers.h"
// Sets default values
AFirewallV2::AFirewallV2()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
Hitbox = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Hitbox"));
RootComponent = Hitbox;
static ConstructorHelpers::FObjectFinder<UStaticMesh> WallHitbox(TEXT("StaticMesh'/Game/muro.muro'"));
if (WallHitbox.Succeeded()) Hitbox->SetStaticMesh(WallHitbox.Object);
}
#pragma region Default functions
// Called when the game starts or when spawned
void AFirewallV2::BeginPlay()
{
Super::BeginPlay();
this->Hitbox->OnComponentBeginOverlap.AddDynamic(this, &AFirewallV2::OnOverlapBegin);
try
{
GetWorld()->GetTimerManager().SetTimer(WallDurationHandle, this, &AFirewallV2::TimerCallback, WallDuration, false);
}catch(_exception){}
}
// Called every frame
void AFirewallV2::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
#pragma endregion
void AFirewallV2::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
bool bFromSweep, const FHitResult& SweepResult)
{
}
void AFirewallV2::TimerCallback()
{
Destroy();
}
.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Engine/EngineTypes.h"
#include "FirewallV2.generated.h"
UCLASS()
class WHYISTHISSOHARD_API AFirewallV2 : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AFirewallV2();
UPROPERTY()
class UStaticMeshComponent* Hitbox;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float Damage = 10.f;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float WallDuration = 10.f;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float TickInterval = 5.f;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
UFUNCTION()
void OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
bool bFromSweep, const FHitResult& SweepResult);
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UFUNCTION()
void TimerCallback();
FTimerHandle WallDurationHandle;
};
Any help would be appreciated. Thanks!