LEAP Documentation 40220
Documentation for the LEAP project
ActorSpawningVolume.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2018. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "GameFramework/Actor.h"
7#include "Runtime/Engine/Classes/Engine/EngineTypes.h"
8#include "Runtime/Core/Public/Containers/EnumAsByte.h"
9#include "Components/BoxComponent.h"
10#include "ReactsToMatchEvents.h"
11#include "ProjectXGameMode.h"
12#include "SpawnInterface.h"
13#include "ActorSpawningVolume.generated.h"
14
16
17UCLASS()
18class PROJECTX_API AActorSpawningVolume : public AActor, public IReactsToMatchEvents, public ISpawnInterface
19{
20 GENERATED_BODY()
21
22public:
23 /* Run when the match starts, if false, the spawner will begin spawning actors immediately. */
24 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SpawningVolume, meta = (EditCondition = "!bExecutesOnBeginPlay"))
25 bool bExecuteOnMatchStart = true;
26 /* Run when the match starts, if false, the spawner will begin spawning actors immediately. */
27 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SpawningVolume, meta = (EditCondition = "!bExecuteOnMatchStart"))
28 bool bExecutesOnBeginPlay = false;
29 /* List of possible actors to spawn. */
30 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SpawningVolume)
31 TArray<FActorSpawnInfo> ActorsToSpawn;
32 /* Randomly chooses a value between min and max, waits that amount of time before spawning the first actor. */
33 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SpawningVolume)
34 FVector2D SpawnInitialDelay = FVector2D(5.0f, 10.0f);
35 /* Randomly chooses a value between min and max, waits that amount of time before spawning any subsequent actors. */
36 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SpawningVolume)
37 FVector2D SpawnDelay = FVector2D(5.0f, 10.0f);
38 /* Repeat the delay and spawn x amount of times. -1 is a infinite loop. */
39 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SpawningVolume)
40 int32 LoopCount = -1;
41 /* Should the spawned actor be line-traced to the ground? */
42 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SpawningVolume)
43 bool bGroundActors = false;
44 /* Should we try to snap this point to a navigable space? */
45 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SpawningVolume, meta = (EditCondition = "bGroundActors"))
46 bool bProjectPointToNavigation = false;
47 /* Which trace channel should be used? */
48 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SpawningVolume, meta = (EditCondition = "bGroundActors"))
49 TEnumAsByte<ECollisionChannel> TraceChannel;
50 /* How should we handle actors that attempt to spawn inside collision? */
51 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SpawningVolume, meta = (EditCondition = "bGroundActors"))
52 ESpawnActorCollisionHandlingMethod SpawnCollisionHandling = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
53 /* After all spawning is completed, the spawner will wait this amount of time before destroying itself */
54 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SpawningVolume)
55 float CleanupDelay = 1.0f;
56 /* Constrains the actor spawn volume to this actor's bounds rather than using it's own. */
57 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SpawningVolume)
58 AActor* ActorBoundsOverride = nullptr;
59 /* Match elapsed duration before the ActorBoundsOverride will be used. */
60 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SpawningVolume)
61 float ActorBoundsOverrideGameTime = 0.0f;
62 /* Prints useful information about the state of the spawner. Does not run in ship builds. */
63 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SpawningVolume)
64 bool bDebug = false;
65 /* Should this actor destroy itself when spawning is completed? */
66 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = SpawningVolume)
67 bool bDestroyWhenFinishedSpawning = true;
68
70
71 virtual void BeginSpawning_Implementation() override;
72 virtual void StopSpawning_Implementation() override;
73 virtual bool ImplementsSpawnCompleteCallback() const override { return true; }
74
75 virtual void MatchStarted() override;
76 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
77 virtual void BeginPlay();
78 virtual bool AttemptToGroundPoint(FVector& RandomPoint, const FVector& Origin, const FVector& Extent);
79 virtual void SpawningFinished();
80 AStartPointVolume* GetRandomSpawnVolume() const;
81
82 UFUNCTION(BlueprintImplementableEvent, Category = SpawningVolume)
83 void SpawningCompleted();
84
85private:
86 FTimerHandle SpawnTimer;
87
88 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = SpawningVolume, meta = (AllowPrivateAccess = true))
89 TArray<AStartPointVolume*> SpawnVolumes;
90 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = SpawningVolume, meta = (AllowPrivateAccess = true))
91 UBoxComponent* BoxComponent;
92
93 int32 ChildSpawnersSpawning = 0;
94 uint16 CurrentLoopCount = 0;
95 TArray<FActorSpawnInfo> ActorsToSpawnCache; //We cache in case this spawner is ever to be reused
96
97 FVector GetRandomPointInBox(const AActor* TransformActor, const FVector& Extent, const FVector& Origin) const;
98 FVector GetSpawnPoint(AStartPointVolume* VolumeOverride = NULL) const;
99
100 void SpawnActor();
101 void CleanupNetObject(AActor* SpawnedActor);
102 void Cleanup();
103
104 UFUNCTION()
105 void OnChildFinishedSpawning(UObject* Spawner);
106
107 TArray<TWeakObjectPtr<AActor>> SpawnedActors;
108 bool bCalledSpawnCompleteEvents = false;
109};
Definition: ActorSpawningVolume.h:19
Definition: StartPointVolume.h:14
Definition: ReactsToMatchEvents.h:16
Definition: SpawnInterface.h:24
Definition: ProjectXGameMode.h:79