Skip to content

Instantly share code, notes, and snippets.

@SoylentGraham
SoylentGraham / gist:bef991c9cd38f9b9c39e549bfcfb05a9
Created September 13, 2017 15:46
Unity Find all objects of type in a scene including inactive
static T[] FindObjectsOfTypeIncludingDisabled<T>()
{
var ActiveScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene ();
var RootObjects = ActiveScene.GetRootGameObjects ();
var MatchObjects = new List<T> ();
foreach (var ro in RootObjects) {
var Matches = ro.GetComponentsInChildren<T> (true);
MatchObjects.AddRange (Matches);
}