Table of Contents
I'm new to pooling! When do I spawn/despawn items?
SmartPool should be used as a replacement for the default instantiation mechanism! So, setup a pool like shown above (by doing so, you connect a pool name with a prefab) and all you need to do is replace calls to Instantiate and Destroy with calls to SmartPool:
- Change Instantiate(myPrefab) to SmartPool.Spawn(“myPoolName”)
- Change Destroy(myPrefab) to SmartPool.Despawn(myInstance)
Whenever you want to instantiate an object, use Spawn instead! Whenever you want to destroy an object, use Despawn instead! It is that simple!
How to initialize objects after spawning?
When you call Spawn() SmartPool will set the object's localPosition to (0,0,0) and enable the GameObject. When despawning, the GameObject will be disabled again. So you should add a script to your prefab and place initialization code in a function OnEnable(), while cleanup code should go to OnDisable().
If you use playMaker just add a FSM to your prefab. The FSM will start playing when the object becomes active.
Create a folder Standard Assets Move the complete SmartPool folder into Standard Assets Move the Editor folder (now under Standard Assets/SmartPool/Editor) up to Standard Assets