playMaker

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

Handrews

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Get all components or scripts
« on: March 14, 2020, 06: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: 389
    • View Profile
Re: Get all components or scripts
« Reply #1 on: March 14, 2020, 10:48:39 AM »
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: 4954
    • View Profile
    • jinxtergames
Re: Get all components or scripts
« Reply #2 on: March 15, 2020, 12: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.