#NVJOB Simple Pool



This is a simple pool for optimizing object loading.
All objects in the pool are loaded during initialization, and then retrieved from the pool and returned back to the pool without sacrificing performance.
The pool allows you to completely abandon Instantiate and Destroy after initialization.

For Unity version of at least 2019.1.8 (64-bit)
Current version 1.2.1
Download from Unity Asset Store Download from GitHub Report a Problem / Issue Tracker / FAQ
#NVJOB Simple Pool. Free Unity Asset.

Getting an object from a pool:

SimplePool.GiveObj() instead of using Instantiate(Object).
SimplePool.GiveObj(numElement)-> numElement - number of the Element in editor (SimplePool).

#NVJOB Simple Pool. Free Unity Asset.

GameObject obj = SimplePool.GiveObj(0);
Checking that the pool is not empty, if the pool is empty it will return null:
GameObject obj = SimplePool.GiveObj(0); if (obj != null) { // All further manipulations with the object. }
After all the transformations of the object, activate it:
obj.SetActive(true);
The number of elements in the editor (SimplePool):
SimplePool.numObjectsList

Return object to the pool, remove from the scene:

SimplePool.Takeobj() instead of using - Destroy(Object).
SimplePool.Takeobj(GameObject)-> GameObject - is an object that to be returned to the pool.
SimplePool.Takeobj(obj);

Example script:

using UnityEngine; public class Example : MonoBehaviour { GameObject obj; void Start() { if(SimplePool.numObjectsList == 0) obj = SimplePool.GiveObj(0); else obj = SimplePool.GiveObj(Random.Range(0, SimplePool.numObjectsList)); if (obj != null) { obj.transform.SetPositionAndRotation(transform.position, transform.rotation); obj.transform.parent = transform; obj.SetActive(true); Invoke("DestroyObject", 5); } } void DestroyObject() { SimplePool.Takeobj(obj); } }

License

This project is licensed under MIT License
(C) Copyright 2016-2020 #NVJOB
Nicholas Veselov Unity Game Developer
Николай Веселов Unity Разработчик Санкт-Петербург