5#include "CoreMinimal.h"
6#include "UObject/NoExportTypes.h"
7#include "SG_ObjectPool.generated.h"
15 template <
typename ActorType>
16 void Reserve(UWorld* World, int32 Num,
const TSubclassOf<AActor>& ActorClass)
20 for (int32 i = 0; i < Num; ++i)
22 ActorType* Actor = World->SpawnActor<ActorType>(ActorClass, FTransform::Identity);
27 template <
typename ActorType>
28 ActorType* Pop(UWorld* World,
const FTransform& Transform,
const TSubclassOf<AActor>& ActorClass)
30 if (!World)
return nullptr;
32 ActorType* Actor = Pool.IsEmpty() ? World->SpawnActor<ActorType>(ActorClass, Transform) : Cast<ActorType>(Pool.Pop());
34 Actor->SetActorTransform(Transform);
35 Actor->SetActorHiddenInGame(
false);
39 template <
typename ActorType>
40 void Add(ActorType* Actor)
43 Actor->SetActorHiddenInGame(
true);
49 TArray<TObjectPtr<AActor>> Pool;
Definition: SG_ObjectPool.h:11