Pool Asset
Class: UObjectPoolClass
Last updated
Class: UObjectPoolClass
Last updated
The Pool Asset is a critical component within the Object Pool Manager system. It defines the blueprint for the objects that will be managed within the pool, including their initialization, lifecycle management, and specific configuration settings. This allows developers to streamline object management, improve performance, and ensure that objects are efficiently recycled and reused.
The Pool Asset encapsulates all necessary information for creating and managing a pool of reusable objects. It specifies which objects are included in the pool, how they are initialized, and the conditions under which they are recycled or expanded. By defining these parameters, the Pool Asset ensures that the Object Pool Manager can handle objects dynamically and efficiently, without unnecessary overhead.
To create a Pool Asset, follow these steps:
Create a New Class: Create a new class that inherits from UObjectPoolClass
. This class will serve as the Pool Asset.
Define Pool Configuration: In the new class, define the object pool objects using the provided variables.
You need to register this asset with a key for global use.
Register assets before using them
Once the Pool Asset is created, it can be used within the Object Pool Manager to manage object pools efficiently. Here’s how to use it:
Add Pool Asset to Object Pool Manager: Register the Pool Asset within the Project Configuration
Initialize Pool Asset: The Object Pool Manager will automatically initialize the Pool Asset based on the defined configuration when the game starts or when the pool is explicitly initialized.
Request and Return Objects: Use the Object Pool Manager’s API to request and return objects from the pool as needed.
Monitor and Debug: Utilize the debugging and monitoring features to ensure the pool operates efficiently and to troubleshoot any issues.
The following are the key variables used in a Pool Asset and their purposes:
ObjectPool: A map that stores the pool data for each registered object. Each entry includes initialization parameters, object references, and lifecycle management settings.
bEnable: A boolean flag indicating whether the object pool is enabled and should be managed by the pool manager.
bRecycleInactiveObjects: Indicates whether inactive objects should be recycled periodically.
RecyclePerCycle: The number of objects to recycle during each cycle.
RecycleThreshold: The threshold below which objects will not be recycled.
bAutoExpandPool: Determines if the pool should automatically expand when needed.
AutoScaleThreshold: The threshold for triggering automatic pool expansion.
AutoScaleAmount: The number of objects to add to the pool when it auto-expands.
InstantSpawn: The number of objects to spawn instantly when the pool is initialized.
DebugPool: Enables debug information for the pool, allowing developers to see detailed information about the pool’s state.