mirror of
https://github.com/storytold/EventCenterPlugin.git
synced 2026-10-09 00:09:42 +00:00
Actor deletion works
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user