Actor deletion works

This commit is contained in:
Brandon Thomas
2021-02-17 05:38:07 -05:00
parent 5d9760447c
commit 4f9b8fc4f9
3 changed files with 25 additions and 2 deletions
@@ -43,3 +43,14 @@ void ASpawnableActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void ASpawnableActor::StartDestroyTimer(float seconds)
{
GetWorldTimerManager().SetTimer(DestroyTimer, this, &ASpawnableActor::InvokeDestroy, seconds);
}
void ASpawnableActor::InvokeDestroy()
{
Destroy();
}
@@ -61,5 +61,7 @@ void ASpawningActor::Spawn()
// TODO(bt): This will memory leak.
ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor(ASpawnableActor::StaticClass());
spawnedActor->SetActorLocationAndRotation(location, rotation, false, 0, ETeleportType::ResetPhysics);
spawnedActor->StartDestroyTimer(10.0);
}
@@ -3,6 +3,7 @@
// Unreal Core
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "Engine/EngineTypes.h"
// EventCenterPlugin
#include "SpawnableActor.generated.h"
@@ -28,12 +29,21 @@ public:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableActor", meta = (AllowPrivateAccess = "true"))
class UStaticMesh* BaseMesh;
/** Set a timer to destroy this actor. */
void StartDestroyTimer(float seconds);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
virtual void BeginDestroy() override;
// Destroy timer callback.
void InvokeDestroy();
// (Optional) destroy callback timer.
FTimerHandle DestroyTimer;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;