#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 GitHub Download from Unity Asset Store Report a Problem / Issue Tracker / FAQ
#NVJOB Nicholas Veselov (nvjob.github.io) | Simple Pool 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 Nicholas Veselov (nvjob.github.io) | Simple Pool 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-2019 #NVJOB
Nicholas Veselov - independent software and assets developer
Website powered by GitHub.com