Skip to content

Repository files navigation

FastPool

Library of scripts to help facilitate the creation of a pool of objects. Uses efficient data structures at its core.

Watch on GitHubStar on GitHub
<< Advantages | How to use | Install | Download >>

Advantages of the library

This library will help you quickly and efficiently develop object pools in your projects. The library is written very simply and intuitively (implements the classic design pattern - the object pool). In addition, this library uses an efficient data structure - FreeList.

After a series of tests of different data structures (Array, List, Queue, Stack, ConcurrentBag and FreeList), the most effective data structure at the core of this library was FreeList. The time required for basic operations is shown below.

0

Thus, FreeList is thousands of times more efficient than familiar data structures.


How to use this library?

  1. First, your pool object must realise the IPoolable interface.
usingUnityEngine;usingFastPool;publicclassSomePoolObject:MonoBehaviour,IPoolable{publicIPoolableNextInactiveObject{get;set;}publicvoidResetStateObject(){// some action for reset state of pool object}}
  1. Secondly, you need to realise an object pool manager script (for example, EnemiesController, which will control the logic of enemies and have objects of enemies).
usingUnityEngine;usingFastPool;publicclassSomePoolManager:MonoBehaviour{[SerializeField]privateSomePoolObjectpoolObjectPrefab;[SerializeField]privateintobjectsCount;privatePoolManager<SomePoolObject>poolManager;privatevoidStart(){Initialize();}privatevoidInitialize(){poolManager=newPoolManager<SomePoolObject>(objectsCount,ObjectGenerator);}privateSomePoolObjectObjectGenerator(){returnInstantiate(poolObjectPrefab);}publicvoidPopObjectsTest(){poolManager.Pop();}publicvoidPushObjectsTest(SomePoolObjectunnecessaryPoolObject){poolManager.Push(unnecessaryPoolObject);}}
  1. Done! Now you can focus on other tasks in your project.

How to install?

  1. Download SimpleLocalization.unitypackage and using UnityPackageManager.
  2. The Unity Package Manager (UPM) is a new method to manage external packages. It keeps package contents separate from your main project files.

Modify your project's Packages/manifest.json file adding this line: "com.lodza.fastpool": "https://github.com/RodionLodza/FastPool.git#package-branch"

To access classes inside of this package you will need to add a reference to com.lodza.fastpool.asmdef to your project's assembly definition file.

License

About

Library of scripts to help facilitate the creation of a pool of objects. Uses efficient data structures at its core.

Topics

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages