playMaker

Author Topic: Adding Game Objects of same Tag in an Array at Runtime  (Read 513 times)

GMPlay

  • Playmaker Newbie
  • *
  • Posts: 28
Adding Game Objects of same Tag in an Array at Runtime
« on: August 15, 2022, 07:28:12 AM »
Newbie Alert! ;D

So I was wondering how do I make a loop such that I can add all game objects of same Tag within a scene into an array...at Runtime.

The thing is, the number of game objects to be added will never be constant and vary scene by scene. Therefore I am not sure if 'Loop State' action will be used in this case.

Although the ORDER in which these Game Objects of same tag that will be added to array doesn't really matter in my case.

Will appreciate any help. Thanks in advance!

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Adding Game Objects of same Tag in an Array at Runtime
« Reply #1 on: August 15, 2022, 12:18:43 PM »
How are these objects being spawned? Or are they present in the scene at the very start?

What kind of objects are they; enemies, environment, hazards, pick-ups etc ?

GMPlay

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Adding Game Objects of same Tag in an Array at Runtime
« Reply #2 on: August 16, 2022, 09:07:42 AM »
Hi thank you for your reply.

I figured out that 'Get Next Child' action is handy for such situation. :)

To answer your question, these  objects will pre-exist in the scene but originate from a prefab. There wont be any spawning.

I used Get Next Child in a loop and added all those objects under a parent. Then I used classic 'Array Add' within the loop.

So far this works, and hope it will continue to do so.