- Home /
Enemies shoot Bullet(pooled)
Hello, In a shmup, I have an enemy shooting bullets. (good start ! :) ) This bullet is pooled and useable by several enemies. Now i want another bullets but i don't know the best solution :
create another bullet with another go pooler or
add another sprite in the current go bullet and then activate the desired sprite when the bullet is active. So in this case, no need to create another pooler ?
Answer by antonsem · Jan 20, 2020 at 11:40 AM
Having multiple pools won't hurt. But if the question is about the performance, usually the answer is to try the easiest solution, and think about the optimization if there is a problem. Premature optimization is the mother of all evil! :D
Usually, I'm using this implementation myself: https://www.anton.website/resource-manager-and-object-pooling/
This implementation uses different pools for different prefabs. One thing to keep in mind is that all of the referenced prefabs will be loaded to memory as soon as the scene with the ResourceManager is loaded. It might be a problem if prefabs are big.
Answer by 9uile · Jan 20, 2020 at 12:11 PM
This is and interesting way to manage pools ! Thank you. What do you think about my idea to deal with bullets ? Different aspect (sprites) but using the same bullet prefab ? - Add another sprite in the current go bullet and then activate the desired sprite when the bullet is active
if it works, i can only have one bullet prefab for multiples bullet aspect. e.g. having only 1 bullet prefab (with 5 sprites) and 1 pooler instead of 5 bullet prefabs and 5 pools.
And another question :) : I a bullet is only use by one gameobject (a boss), is it good to make the objpool a child of the boss ?
Since we are talking about very small prefabs (I mean hopefully your bullet prefabs are small :D) it won't matter from the performance point of view. I would prefer to have multiple prefab variants of a base bullet prefab, ins$$anonymous$$d of trying to change it from code. It will keep the code simpler.
I found an interresting tutorial about pooling objects here. https://www.raywenderlich.com/847-object-pooling-in-unity
very useful
Answer by Stewarrt · Feb 17, 2020 at 08:59 AM
Setting up the shooting, and the ownership of the bullets that are created, is really what this blog is about. When the bullet is created, a few variables need to be updated, such as the owner and the direction the bullet is moving myprepaidcenter
Your answer
![](https://koobas.hobune.stream/wayback/20220612221827im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Shooting with Limited Ammo 2 Answers
Need hep with pooling(call Cs in Js) 0 Answers
Getting Bullets to fire in Direction of Gun Barrel 1 Answer
Bullet facing 0 Answers
How to throw a RigidBody in the direction of Mouse Pointer (3D)? 2 Answers