Created
September 13, 2017 15:46
-
-
Save SoylentGraham/bef991c9cd38f9b9c39e549bfcfb05a9 to your computer and use it in GitHub Desktop.
Unity Find all objects of type in a scene including inactive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 (); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you !!!