PooledObject Pro
|
PooledObject Pro is a C# scripting package intended for Unity3D. It helps improve the ability and efficiency of handling large groups of duplicate objects, has multiple custom features for interacting with these groups of objects, and much more! Use this to more efficiently handle your large amounts of duplicate objects.
Its features include:
The Spawn function: Use this function to create or pull from the pool an object of template objectName.
The Create function: Use this function to forcefully create an object of template objectName even if there's one available in the pool.
The Launch function: Use this function to pull from the pool an object of template objectName. Will not create a new TBPooledObject if there are none available.
The Closest/Farthest funtions: Use these functions to check for the nearest/furthest TBPooledObject of any template listed in toTargetOfTemplateNames parameter.
The Kill function: Use this function to "Destroy" a TBPooledObject and return it to the pool.
The Discard function: Use this function to safely remove a TBPooledObject derived script so that the object then behaves normally again.
The Annihilate function: Use this function to safely and literally DESTROY a TBPooledObject.
The SafeSceneChange function: Use this function to exempt any passive and active TBPooledObjects from destruction on scene change. (Use this if you'd like to preserve your pools as you change scenes, so that you don't have to re-instantiate objects in your new scene).
The Init function: Use this to mark a target GameObject as a template during runtime. This is useful for when you want to create a template of an object only when that object meets a criteria, and you don't know what those criteria will be in compiletime.
The QOL functions. Use these to help you debug your project. You can use them to log the members or template data in runtime.
More features coming!
You can purchase the asset here, and if you encounter any bugs, you can get in contact with the developer though this email.
|
Screenshots & visual info
Pooling/Reusing
(Field highlighted in red). Look at how consistent and low the peaks are for GC Allocated, and see how far the garbage collections are apart! (Yellow-orange line).
|
Instantiation/Destruction
(Field highlighted in red). Look at how inconsistent and often the memory GC Allocated Spikes! This can cause increased memory use and random CPU performance drops.
|
How to use PooledObject Pro
NOTE: Know that it is safe to delete the “Demo” folder at the directory “TB - PooledObject Pro > Demo” and it is safe and recommended to delete the “DemoCube” prefab at the directory “TB - PooledObject Pro > Resources > POTemplates > DemoCube” once you have decided you don’t need the demo anymore.
This portion of the tutorial is in-depth, so if you’re looking for a quick start, scroll down to the Quick Start section below.
*In-Depth tutorial still in progress*
Quick Start
First of all, to get our object pooling system working, we need to designate some TBPooledObject Prefabs. To do this, we need to create some prefabs by dragging them into our project directory; in the “TB - PooledObject Pro > Resources > POTemplates” folder. (Make sure your prefab has a TBPooledObject derived script on it. (If you don’t know what that means, just change the “MonoBehaviour” at the top of the class to “TBPooledObject”).). Now that that is done, we need to figure out the ways to use the TBPooledOBject functions to begin using our object pool. Listed below are the ways to “Create”, “Destroy”, and do basic general interactions with our pooled objects.
- The Spawn(string objectName) Function: The basic concept behind this function is that if there are any unused objects in the pool of “objectName”, it will take one and reset it, then return that object as the spawned pooled object. However, if there are no pooled objects in the object pool, Spawn() will create a new one instead. To use this function, pass the prefabs name EXACTLY as it is spelled in the “TB - PooledObject Pro > Resources > POTemplates” folder. There are function overloads so you can apply your position, rotation, and scale.
- The Launch(string objectName) Function: This function will check the pool for an unused object, reset it, and return it. This function will NOT instantiate a new object if there are none available in the pool. This function has overloads just like the Spawn() function to apply your position, rotation, and scale.
- The Create(string objectName) Function: This function will forcefully create a new pooled object even if there are some available to reuse. This function has overloads just like the Spawn() and Launch() functions to apply your position, rotation, and scale.
- The Kill(TBPooledObject target) Function: Use this function instead of the Destroy() function whenever you want to mark an object as reusable. (You can also use KillMe() to kill a TBPooledObject).
- The OnReset() Function: Note: Never call this function manually. Instead, make an override in your TBPooledObject derived script to reset additional stuff whenever the pooled object is reused. (For example, when your object is reset upon reuse, you probably want to reset rigidbody velocities, to do this, simply put that code in the OnReset() override).