playMaker

Author Topic: Get all components or scripts  (Read 1851 times)

Handrews

  • Playmaker Newbie
  • *
  • Posts: 36
  • 3D Artist & Game Developer
    • Thetra Games Artstation
Get all components or scripts
« on: March 14, 2020, 09:45:31 AM »
Hi!

I'm looking for the way to get all the components or scripts of the same type in a scene.

For example, i have a script called "Outline" and i need to find and store all of this scripts in the whole scene, for all the game objects in it.

Is it posible?

Ty

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Get all components or scripts
« Reply #1 on: March 14, 2020, 01:48:39 PM »
That looks like an expensive procedure. You could loop over all objects in the hierarchy, then check the with get component if it’s present and store the result in an array. My tip would be checking out array actions, and get component.

You could also do this the other way, have each game object with said component register itself with an FSM.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Get all components or scripts
« Reply #2 on: March 15, 2020, 03:59:48 AM »
Hi.
you should indeed do this at the start of your scene and not somewhere in between.

Also you might want to look into Array Maker as its more advanced than the included Array's

With array list you could use 'Array List Get All Child Of Game Object'
then loop thru them with 'Array List Get Next' and check with 'Has Component'
then store in a different array.