| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
An Updated Object pooler to increase performance when pooling many objects.
It is computationally expensive to instantiate and destroy objects, such as bullets, that get re-used a lot. Its a lot more performant to instantiate them all and to keep reference and to recycle them.
To use this object pool you will need to create a script for every pool you will need, and only one object is allowed per pool.
Queue is benificial to use because it acts similar to a LinkedList in C++. With a Queue, when we Dequeue an object it Pops the first element from the Queue. When we Enqueue an object, it is added to the end of the queue, creating a first in, first out system. We will not need to access objects at specific indecies, therefor a Queue is perfect for what we need. Read More about when to use Lists or Queues here!
public class GenericPool : GenericObjectPool<ObjectTobePooled>
{
public override void AddPoolReference(ObjectTobePooled objectToAddReference) => objectToAddReference.GetComponent<IObjectPool>().pool = this;
}
internal interface IObjectPool
{
public GenericPool pool { get; set; }
}
To access the pool, we want to call our new PoolScript and use the Get() method to return the object we have pooled.
| Back | FazBrowse Home | New Git URL |