I’ve been plodding along following the tutorials and advice on here and now have my spaceship firing and moving. However, i’ve seen some discussion on the best way to create a bullet and it seems that dynamically created bullets can be a little resource heavy. Anyone have experience on this; is dynamic creation ok or is a pooled resource method better? If the latter, what’s the best way to set up a pool of ready made bullets?
A pre-instantiated pool of bullets will give you much better performance (at the small cost of instantiating them all at startup).
Create a bullet manager script, which instantiates a set number of bullets at startup. As you instantiate each one, add it to an array.
Then, when firing, cycle through each item in the array and use the bullet at that position in the array.
All you need to do is decide on a maximum number of bullets ![]()
- Ben
I see where that could be a big help.
Would the speed advantage be as noticeable on an older Invaders style game (where the player has for example just 2 bullets onscreen at once) as on a constant-streaming bullets of a graphic heavy shooter?
Hey there,
The shooting mechanism implemented in the Star Trooper iPhone tutorial should help you with this. you can find it on the unity iphone tutorials page
That’s something you’ll have to try. It’s possible the performance hit from instantiate in that case is negligable. I don’t have first-hand experience of this, but I’ve heard that even instantiating just a single object can cause a visible performance blip on the iphone (although that may have been related to a ‘heavier’ object with a meshcollider, perhaps).
For iPhone, you really have to test, tune repeat ![]()
- Ben