Playmaker Forum

PlayMaker News => General Discussion => Topic started by: Handrews on March 14, 2020, 09:45:31 AM

Title: Get all components or scripts
Post by: Handrews 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
Title: Re: Get all components or scripts
Post by: Thore 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.
Title: Re: Get all components or scripts
Post by: djaydino 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 (https://hutonggames.fogbugz.com/default.asp?W715) 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.