Editor - Filtering Resources.FindObjectsOfTypeAll

Hi guys,

Was wondering if anyone knew of a method to filter objects returned by Resources.FindObjectsOfTypeAll in the editor?

I am trying to create a plugin which alters all UnityEngine.UI.Text components in a scene however Object.FindObjectsOfType does not return disabled objects (and I want this plugin to iterate over all instances of the Text component).

If this was my own class I would have tracked the instances using a static list in the class but alas this is not the case as it is the built in Unity UI Text component.

I am trying to use Resources.FindObjectsOfTypeAll however I have a feeling that this is causing the plugin to hang in certain situations as it is trying to alter resources that are not GameObjects in the current scene which is open (i.e. I think it might be trying to alter a prefab which is not behaviour I desire).

Is there any way to filter the results, for example:

if(object is GameObject)
{
// Do stuff.
}
else
{
// Dont do stuff.
}

Any advice on this would be greatly appreciated.

Cheers,

John

Generally, if you want to filter a list I’d recommend Linq.

using System.Linq

Object[] gameObjects = Resources.FindObjectsOfTypeAll(type).Where(a => a is GameObject).ToArray();

Thanks for the reply.

Actually found a better (undocumented) way of doing it without Resources.FindObjectsOfTypeAll.

Link to solution here: Finding the root GameObjects in the scene ? - Questions & Answers - Unity Discussions