Quickly find all particles on the scene without using GetComponent
I need to quickly find all particles on the scene without using GetComponent. Perhaps in the engine there is some pool of all existing particles at the moment to have direct access to them? Like Scene.GetRootGameObjects () to find all root objects, but for particles or objects with particle systems.
Answer by Bunny83 · Mar 21, 2018 at 02:50 AM
Quickly? not really. You can use FindObjectsOfType with any type derived from UnityEngine.Object which does include any components as well. However the method has to search through the internal tracking list of all objects (that includes Materials, Meshes, GameObject, Components, ScriptableObjects, Prefabs, ...). If you call this once it shouldn't be a huge problem. Though it depends on how many tracked objects there are. For example using GetComponentsInChildren on a parent object should be more efficient than FindObjectsOfType. Though it only works of all objects are below a common parent object.
If you need to access the particle systems on a regular basis you may want to store them yourself in a central List.