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); 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. // TODO(bt): This will memory leak.
ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor(ASpawnableActor::StaticClass()); ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor(ASpawnableActor::StaticClass());
spawnedActor->SetActorLocationAndRotation(location, rotation, false, 0, ETeleportType::ResetPhysics); spawnedActor->SetActorLocationAndRotation(location, rotation, false, 0, ETeleportType::ResetPhysics);
spawnedActor->StartDestroyTimer(10.0);
} }
@@ -3,6 +3,7 @@
// Unreal Core // Unreal Core
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "UObject/NoExportTypes.h" #include "UObject/NoExportTypes.h"
#include "Engine/EngineTypes.h"
// EventCenterPlugin // EventCenterPlugin
#include "SpawnableActor.generated.h" #include "SpawnableActor.generated.h"
@@ -22,11 +23,14 @@ public:
/** Mesh to use */ /** Mesh to use */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableActor", meta = (AllowPrivateAccess = "true")) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableActor", meta = (AllowPrivateAccess = "true"))
class UStaticMeshComponent* BaseMeshComponent; class UStaticMeshComponent* BaseMeshComponent;
/** Mesh to use */ /** Mesh to use */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableActor", meta = (AllowPrivateAccess = "true")) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawnableActor", meta = (AllowPrivateAccess = "true"))
class UStaticMesh* BaseMesh; class UStaticMesh* BaseMesh;
/** Set a timer to destroy this actor. */
void StartDestroyTimer(float seconds);
protected: protected:
// Called when the game starts or when spawned // Called when the game starts or when spawned
@@ -34,6 +38,12 @@ protected:
virtual void BeginDestroy() override; virtual void BeginDestroy() override;
// Destroy timer callback.
void InvokeDestroy();
// (Optional) destroy callback timer.
FTimerHandle DestroyTimer;
public: public:
// Called every frame // Called every frame
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;