You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-5Lines changed: 23 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,26 @@
1
1
# Unity-Object-Pool
2
-
A singleton object pooler for all of your optimization. It can handle all of the object pooling during the game loading and is persistant throughout scenes
3
-
4
-
Currently to get the objects from the pool you need to know the position in the pool, will be changed to either use the position or the name.
5
-
2
+
A very simple singleton object pooler for optimization. It can handle all of the object pooling during the game loading and is persistant throughout scenes
3
+
4
+
Currently to get the objects from the pool you need to know the index in the pool, will be changed to either use the position or the name.
5
+
# What is pooling?
6
+
It is computationally expensive to instantiate and destroy objects like bullets that get re-used a lot.
7
+
Its a lot more effective to instantiate them all in the beginning and to keep re-using them by setting them active/false
8
+
9
+
This script can act as a pooling control hub, it will create all pooled objects you need at the start and objects can be called as and when needed by other scripts.
10
+
11
+
## How to setup
12
+
1) Create a new empty GameObject
13
+
2) Create a new script called ObjectPooler and attach it to the GameObject
14
+
3) Replace the contents of ObjectPooler with contents of the ObjectPooler script that can be found in this repo.
15
+
4) In the inspector, in the script component, enter the number of gameObjects you want pooled and then add their prefabs to the list.
16
+
5) Increase Amount to Pool to at least 1. You can also check the 'Load More If None Left' box if you are unsure on how many you will need
17
+
6) Access the Pooled Objects by using
18
+
19
+
```
20
+
GameObject GO = ObjectPooler.Instance.GetGameObject(/*Index of the Pooled Object*/);
0 commit comments