Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: Vanyfraise on December 13, 2017, 06:00:31 AM
-
Hi guys,
I'm searching for a non-developper friendly way to find multiples objects with tag or something else in my scene. I want to build a cancel bullet feature in my shmup. To do this, i have to find all existing bullets in screen and then deactivate them or thing like that.
Do I have to put all created bullet in an array or something like that ?
As Leeloo said, "Please help".
-
There are plenty of ways to do this, i use Pooly for stuff like this but there are also some great pooling actions on the ecosystem and you always want to use pooling when dealing with bullets.
In the Fsm where you fire/spawn your bullet just save a reference to it and store that reference into an array with a max lenght of about 10, that way you can always get the last 10 bullets fired and do a "for each" loop to destroy/despawn them.
(There are some great video's on youtube for learing arrays)
Alternatively you could also parent the bullets to a "Holder" object when spawning them and then use get child/get all children on that parent object.
But the first option would be the most logical thing to do.
Hope that helps
-
I avoid object pooling, always thought it was too complicate for me to play with but it seems i have to.
I'll try Pooly, thakn you !
-
Pooling is really easy, try the free pooling actions on the ecosystem before buying Pooly.
You can still do what you want without pooling offcourse, however pooling is always the smart thing to do when spawning many object like this.
-
If it's not a design problem and bullets need to have a specific parent, that solutiin seems simplest, simply parent them under an object and then just despawn all children.
-
Hi.
You can add the bullets to an array when creating (or when enabling when pooling)
Then you can use array get next to loop thru them and destroy (or disable and place back in pool)
I do agree that it is best to use pooling as it is a lot better for performance.
-
Thanks guys,
I tried "Simple Object Pooling", it works great.