Skip to content

ertanturan/Unity-Object-Pooling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

21c1c3c · Jan 5, 2023

History

92 Commits
Jan 5, 2023
Jan 5, 2023
Nov 19, 2022
Jan 5, 2023
Jan 5, 2023
Sep 26, 2019
Sep 26, 2019
Nov 27, 2022
Nov 27, 2022
Aug 28, 2020
Nov 20, 2022
Jan 5, 2023
Dec 25, 2019

Repository files navigation

Runtime-extendible Object-pooler within unity

This pool creates objects that you defined on start and creates additionally if more spawn request comes to the pool than pools capacity and manages newly added pool objects too ! .

Pre-requisit(s)

  • Zenject IOC (Find HERE )

Import

  1. Go to release page.
  2. Download the lates release of the package.
  3. Import it to your unity project.

Usage

  1. Add ObjectPooler component to an object
  2. Set a size for the pool.
  3. Create prefabs to pool
  4. Edit PooledObjectType.cs class according to your prefabs which you want to pool
  5. Go to the scene object with ObjectPooler component and assign prefabs and enums and set size for each pooled object.
  6. Ready to go !

To Spawn and Despawn

Inject the pooler to your script

(This part assumes you've set-up your zenject installer and contexts)

[Inject]
private ObjectPooler _pooler;

Spawn

_pooler.SpawnFromPool(PooledObjectType.YourTypeComesHere , YourVector3PositionComesHere, YourQuaternionRotationComesHere,Optional_YourParentTransformComesHere,Optional_PooledObjectInitializationArgsComesHere);  

Despawn

_pooler.Despawn(gameObject); 

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Credits

  • Zenject - used for dependency injection

I would like to extend a special thank you to the creators and maintainers of Zenject for their excellent work on this dependency injection framework. Their contributions have greatly improved the functionality and usability of this project.

ENJOY !