- Home /
Best way of getting all object instances in a scene from an editor class
Hi all,
Basically I want to have a helper method for getting all object instances in a scene, including inactive ones. It will be used in editor scripts. Is the following the best way of doing it?
static public T[] FindAllObjectsInScene<T>() where T : Component
{
T[] allObjects = Resources.FindObjectsOfTypeAll(typeof(T)) as T[];
List<T> sceneObjects = new List<T>();
foreach(T obj in allObjects)
{
PrefabType pfType = PrefabUtility.GetPrefabType(obj);
if(pfType != PrefabType.Prefab &&
pfType != PrefabType.ModelPrefab)
{
sceneObjects.Add(obj);
}
}
return sceneObjects.ToArray();
}
Thanks!
Comment
Your answer

Follow this Question
Related Questions
ReImport in c# of GameObjects only for Scene Objects, not assets? 1 Answer
Editor Script, Index Out of Range Exception after Play 1 Answer
TexturePropertySingleLine in Editor class 0 Answers
Change position using custom and native editor 1 Answer
Gizmos.DrawLine is dissapearing after returning to editor after Playing the scene 0 Answers