ashish.patel@portfolio:~$ notes

Optimizing Treasure Systems with Object Pooling in Unreal Engine 5

This technical note explores how I implemented an object pooling system in Unreal Engine 5 to optimize treasure spawning from breakable gameplay objects while improving performance and scalability.

Published in Category:

Analysis

Read time:

INTRODUCTION

While building gameplay systems in Unreal Engine 5, I created breakable objects that reward the player with collectible treasure items.

Initially, every destroyed object spawned a completely new treasure actor during gameplay. Although this worked for small tests, repeatedly spawning and destroying actors quickly became inefficient as the number of breakable objects increased.

To improve performance and scalability, I implemented an object pooling system for treasure actors.


SYSTEM GOALS

The pooling system was designed to:

• reduce repeated actor spawning
• improve gameplay performance
• reuse treasure actors efficiently
• support larger gameplay areas
• optimize breakable object systems
• keep gameplay systems scalable


WHY OBJECT POOLING?

Normally, gameplay systems constantly create and destroy temporary actors during runtime.

Example:

• break object
• spawn treasure
• collect treasure
• destroy treasure actor

Repeating this process frequently can increase memory allocations and runtime overhead.

Instead of destroying actors completely, object pooling allows actors to be reused multiple times.


The workflow becomes:

• request pooled actor
• activate actor
• use actor
• deactivate actor
• return actor back to pool



TREASURE POOL SYSTEM

A dedicated treasure pool manager stores reusable treasure actors inside an array.

CODE EXAMPLE

UPROPERTY()
TArray<ATreasure*> TreasurePool

UPROPERTY()
TArray<ATreasure*> TreasurePool

UPROPERTY()
TArray<ATreasure*> TreasurePool


PRE-SPAWNING TREASURE ACTORS

Treasure actors are spawned once during initialization and hidden until needed during gameplay.

CODE EXAMPLE

ATreasure* Treasure =
GetWorld()->SpawnActor<ATreasure>(
    TreasureClass,
    FVector::ZeroVector,
    FRotator::ZeroRotator
);

Treasure->SetActorHiddenInGame(true);
Treasure->SetActorEnableCollision(false);

TreasurePool.Add(Treasure)

ATreasure* Treasure =
GetWorld()->SpawnActor<ATreasure>(
    TreasureClass,
    FVector::ZeroVector,
    FRotator::ZeroRotator
);

Treasure->SetActorHiddenInGame(true);
Treasure->SetActorEnableCollision(false);

TreasurePool.Add(Treasure)

ATreasure* Treasure =
GetWorld()->SpawnActor<ATreasure>(
    TreasureClass,
    FVector::ZeroVector,
    FRotator::ZeroRotator
);

Treasure->SetActorHiddenInGame(true);
Treasure->SetActorEnableCollision(false);

TreasurePool.Add(Treasure)



REQUESTING A TREASURE FROM THE POOL

When a breakable actor is destroyed, the system requests an available treasure actor from the pool.

CODE EXAMPLE

ATreasure* ATreasurePool::GetPooledTreasure()
{
    for (ATreasure* Treasure : TreasurePool)
    {
        if (!Treasure->IsActive())
        {
            return Treasure;
        }
    }

    return nullptr;
}
ATreasure* ATreasurePool::GetPooledTreasure()
{
    for (ATreasure* Treasure : TreasurePool)
    {
        if (!Treasure->IsActive())
        {
            return Treasure;
        }
    }

    return nullptr;
}
ATreasure* ATreasurePool::GetPooledTreasure()
{
    for (ATreasure* Treasure : TreasurePool)
    {
        if (!Treasure->IsActive())
        {
            return Treasure;
        }
    }

    return nullptr;
}



USING THE POOLED TREASURE

After retrieving a pooled actor, the treasure is activated and positioned at the desired spawn location.

CODE EXAMPLE

ATreasure* Treasure =
TreasurePool->GetPooledTreasure();

if (Treasure)
{
    Treasure->SetActorLocation(SpawnLocation);
    Treasure->ActivateTreasure();
}
ATreasure* Treasure =
TreasurePool->GetPooledTreasure();

if (Treasure)
{
    Treasure->SetActorLocation(SpawnLocation);
    Treasure->ActivateTreasure();
}
ATreasure* Treasure =
TreasurePool->GetPooledTreasure();

if (Treasure)
{
    Treasure->SetActorLocation(SpawnLocation);
    Treasure->ActivateTreasure();
}



RETURNING TREASURE TO THE POOL

Instead of destroying the treasure actor after collection, the actor is hidden and returned back to the pool for future reuse.

CODE EXAMPLE

Treasure->SetActorHiddenInGame(true);
Treasure->SetActorEnableCollision(false)

Treasure->SetActorHiddenInGame(true);
Treasure->SetActorEnableCollision(false)

Treasure->SetActorHiddenInGame(true);
Treasure->SetActorEnableCollision(false)



GAMEPLAY BENEFITS

The pooling system improved:

• runtime performance
• gameplay stability
• memory usage
• scalability for larger levels
• responsiveness during gameplay

The system also reduced unnecessary actor creation during heavy gameplay interactions involving multiple breakable objects.



WHAT I LEARNED

Through this system, I improved my understanding of:

• object pooling architecture
• gameplay optimization
• actor lifecycle management
• scalable gameplay systems
• Unreal Engine 5 performance workflows
• reusable C++ gameplay design

Implementing object pooling helped me better understand how performance optimization becomes increasingly important as gameplay systems grow in complexity.

Tutorial

7 Minute Read

Implementing Weapon Equip & Combat Systems in Unreal Engine 5

This technical note covers how I built a modular weapon equip and combat system in Unreal Engine 5 using sockets, animation montages, overlap detection, and scalable C++ gameplay logic.

Tutorial

6 Minute Read

Save & Load System Using Unreal Engine 5

To preserve player progress between sessions, I built a complete save and load system in Unreal Engine 5 using SaveGame objects, gameplay state serialization, and slot-based saving in C++.

Analysis

5 Minute Read

Team-Based Enemy Combat Using FGenericTeamId

While building enemy combat systems in Unreal Engine 5, I needed a way to prevent enemies from damaging allies. This note covers how I implemented team-based AI combat using FGenericTeamId and attitude checks in C++.

© Ashish Patel | 2026

Gameplay Programmer • Unreal Engine 5 • C++

Create a free website with Framer, the website builder loved by startups, designers and agencies.