From 74b73aad4967c1ac5c808f64196d13c1890f6a01 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 17 Feb 2021 05:40:44 -0500 Subject: [PATCH] better comments / cleanup --- .../Private/SpawningActor.cpp | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/Source/EventCenterPlugin/Private/SpawningActor.cpp b/Source/EventCenterPlugin/Private/SpawningActor.cpp index b1ec3aa..6138fc0 100644 --- a/Source/EventCenterPlugin/Private/SpawningActor.cpp +++ b/Source/EventCenterPlugin/Private/SpawningActor.cpp @@ -39,29 +39,22 @@ void ASpawningActor::Tick(float DeltaTime) void ASpawningActor::Spawn() { + // Spawn actor + // TODO(bt): This will memory leak. + ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor(ASpawnableActor::StaticClass()); + + // Teleport actor randomly + // TODO(bt): Put this in front of the camera, or on the (camera -> player) arc! float x = FMath::RandRange(-1000.0f, 1000.0f); float y = FMath::RandRange(-1000.0f, 1000.0f); float z = FMath::RandRange(-1000.0f, 1000.0f); FVector location(x, y, z); FRotator rotation; - - /*ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor( - ASpawnableActor::StaticClass(), - NAME_None, - &location, - &rotation, - nullptr, // ?? - false, // bNoCollisionFail - false, // ?? - nullptr, // owner - nullptr // instigator - );*/ - - // TODO(bt): This will memory leak. - ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor(ASpawnableActor::StaticClass()); spawnedActor->SetActorLocationAndRotation(location, rotation, false, 0, ETeleportType::ResetPhysics); + // We don't want to keep the actor around indefinitely since they may pile up unused. + // Optionally, we could maintain a queue and cull the oldest actors. spawnedActor->StartDestroyTimer(10.0); }