Skip to content

Instantly share code, notes, and snippets.

@SoylentGraham
Created September 13, 2017 15:46
Show Gist options
  • Save SoylentGraham/bef991c9cd38f9b9c39e549bfcfb05a9 to your computer and use it in GitHub Desktop.
Save SoylentGraham/bef991c9cd38f9b9c39e549bfcfb05a9 to your computer and use it in GitHub Desktop.
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);
}
return MatchObjects.ToArray ();
}
@Morgan-6Freedom
Copy link

Thank you !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment