playMaker

Author Topic: [SOLVED] How to find multiples objects.  (Read 292 times)

Vanyfraise

  • Playmaker Newbie
  • *
  • Posts: 13
    • View Profile
[SOLVED] How to find multiples objects.
« on: December 13, 2017, 04: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".
« Last Edit: February 13, 2018, 06:51:57 AM by Vanyfraise »

LordHorusNL

  • Full Member
  • ***
  • Posts: 108
    • View Profile
Re: How to find multiples objects.
« Reply #1 on: December 13, 2017, 08:19:45 AM »
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
« Last Edit: December 13, 2017, 08:39:36 AM by LordHorusNL »

Vanyfraise

  • Playmaker Newbie
  • *
  • Posts: 13
    • View Profile
Re: How to find multiples objects.
« Reply #2 on: December 13, 2017, 08:40:52 AM »
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 !

LordHorusNL

  • Full Member
  • ***
  • Posts: 108
    • View Profile
Re: How to find multiples objects.
« Reply #3 on: December 13, 2017, 08:49:12 AM »
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.

krmko

  • Hero Member
  • *****
  • Posts: 629
    • View Profile
    • Fat Pug Studio
Re: How to find multiples objects.
« Reply #4 on: December 13, 2017, 09:38:30 AM »
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.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2952
    • View Profile
    • jinxtergames
Re: How to find multiples objects.
« Reply #5 on: December 13, 2017, 10:12:45 AM »
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.

Vanyfraise

  • Playmaker Newbie
  • *
  • Posts: 13
    • View Profile
Re: [SOLVED] How to find multiples objects.
« Reply #6 on: February 13, 2018, 06:52:55 AM »
Thanks guys,
I tried "Simple Object Pooling", it works great.