Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Resources.FindObjectsOfTypeAll

static function FindObjectsOfTypeAll(type: Type): Object[];
static Object[] FindObjectsOfTypeAll(Type type);
static def FindObjectsOfTypeAll(type as Type) as Object[]

Parameters

typeType of the class to match while searching.

Returns

Object[] An array of objects whose class is type or is derived from type.

Description

Returns a list of all objects of Type type.

This function can return any type of Unity object that is loaded, including game objects, prefabs, materials, meshes, textures, etc. It will also list internal stuff, therefore please be extra careful the way you handle the returned objects. Contrary to Object.FindObjectsOfType this function will also list disabled objects.

Please note that this function is very slow and is not recommended to be used every frame.

	// This script displays the number of allocated Unity objects by type.
	// This is useful for finding leaks. Knowing the type of object
	// (mesh, texture, sound clip, game object) that is getting leaked is
	// the first step. You could then print the names  of all leaked assets of that type.

function OnGUI () { GUILayout.Label("All " + Resources.FindObjectsOfTypeAll(typeof(UnityEngine.Object)).Length); GUILayout.Label("Textures " + Resources.FindObjectsOfTypeAll(typeof(Texture)).Length); GUILayout.Label("AudioClips " + Resources.FindObjectsOfTypeAll(typeof(AudioClip)).Length); GUILayout.Label("Meshes " + Resources.FindObjectsOfTypeAll(typeof(Mesh)).Length); GUILayout.Label("Materials " + Resources.FindObjectsOfTypeAll(typeof(Material)).Length); GUILayout.Label("GameObjects " + Resources.FindObjectsOfTypeAll(typeof(GameObject)).Length); GUILayout.Label("Components " + Resources.FindObjectsOfTypeAll(typeof(Component)).Length); }

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void OnGUI() {
        GUILayout.Label("All " + Resources.FindObjectsOfTypeAll(typeof(UnityEngine.Object)).Length);
        GUILayout.Label("Textures " + Resources.FindObjectsOfTypeAll(typeof(Texture)).Length);
        GUILayout.Label("AudioClips " + Resources.FindObjectsOfTypeAll(typeof(AudioClip)).Length);
        GUILayout.Label("Meshes " + Resources.FindObjectsOfTypeAll(typeof(Mesh)).Length);
        GUILayout.Label("Materials " + Resources.FindObjectsOfTypeAll(typeof(Material)).Length);
        GUILayout.Label("GameObjects " + Resources.FindObjectsOfTypeAll(typeof(GameObject)).Length);
        GUILayout.Label("Components " + Resources.FindObjectsOfTypeAll(typeof(Component)).Length);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def OnGUI() as void:
		GUILayout.Label(('All ' + Resources.FindObjectsOfTypeAll(typeof(UnityEngine.Object)).Length))
		GUILayout.Label(('Textures ' + Resources.FindObjectsOfTypeAll(typeof(Texture)).Length))
		GUILayout.Label(('AudioClips ' + Resources.FindObjectsOfTypeAll(typeof(AudioClip)).Length))
		GUILayout.Label(('Meshes ' + Resources.FindObjectsOfTypeAll(typeof(Mesh)).Length))
		GUILayout.Label(('Materials ' + Resources.FindObjectsOfTypeAll(typeof(Material)).Length))
		GUILayout.Label(('GameObjects ' + Resources.FindObjectsOfTypeAll(typeof(GameObject)).Length))
		GUILayout.Label(('Components ' + Resources.FindObjectsOfTypeAll(typeof(Component)).Length))

import System.Collections.Generic;

// This script finds all the objects in scene, excluding prefabs: function GetAllObjectsInScene(): List.<GameObject> { var objectsInScene: List.<GameObject> = new List.<GameObject>(); for (var go: GameObject in Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[]) { if (go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave) continue; var assetPath: String = AssetDatabase.GetAssetPath(go.transform.root.gameObject); if (!String.IsNullOrEmpty(assetPath)) continue; objectsInScene.Add(go); } return objectsInScene; }

static function FindObjectsOfTypeAll(): T[];
static T[] FindObjectsOfTypeAll();
static def FindObjectsOfTypeAll() as T[]

Description

Returns a list of all objects of Type T.

This function can return any type of Unity object that is loaded, including game objects, prefabs, materials, meshes, textures, etc. It will also list internal stuff, therefore please be extra careful the way you handle the returned objects. Contrary to Object.FindObjectsOfType this function will also list disabled objects.

Please note that this function is very slow and is not recommended to be used every frame.

	// This script displays the number of allocated Unity objects by type.
	// This is useful for finding leaks. Knowing the type of object
	// (mesh, texture, sound clip, game object) that is getting leaked is
	// the first step. You could then print the names  of all leaked assets of that type.

function OnGUI () { GUILayout.Label("All " + Resources.FindObjectsOfTypeAll.<UnityEngine.Object>().Length); GUILayout.Label("Textures " + Resources.FindObjectsOfTypeAll.<Texture>().Length); GUILayout.Label("AudioClips " + Resources.FindObjectsOfTypeAll.<AudioClip>().Length); GUILayout.Label("Meshes " + Resources.FindObjectsOfTypeAll.<Mesh>().Length); GUILayout.Label("Materials " + Resources.FindObjectsOfTypeAll.<Material>().Length); GUILayout.Label("GameObjects " + Resources.FindObjectsOfTypeAll.<GameObject>().Length); GUILayout.Label("Components " + Resources.FindObjectsOfTypeAll.<Component>().Length); }

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void OnGUI() {
        GUILayout.Label("All " + Resources.FindObjectsOfTypeAll<Object>().Length);
        GUILayout.Label("Textures " + Resources.FindObjectsOfTypeAll<Texture>().Length);
        GUILayout.Label("AudioClips " + Resources.FindObjectsOfTypeAll<AudioClip>().Length);
        GUILayout.Label("Meshes " + Resources.FindObjectsOfTypeAll<Mesh>().Length);
        GUILayout.Label("Materials " + Resources.FindObjectsOfTypeAll<Material>().Length);
        GUILayout.Label("GameObjects " + Resources.FindObjectsOfTypeAll<GameObject>().Length);
        GUILayout.Label("Components " + Resources.FindObjectsOfTypeAll<Component>().Length);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def OnGUI() as void:
		GUILayout.Label(('All ' + Resources.FindObjectsOfTypeAll[of Object]().Length))
		GUILayout.Label(('Textures ' + Resources.FindObjectsOfTypeAll[of Texture]().Length))
		GUILayout.Label(('AudioClips ' + Resources.FindObjectsOfTypeAll[of AudioClip]().Length))
		GUILayout.Label(('Meshes ' + Resources.FindObjectsOfTypeAll[of Mesh]().Length))
		GUILayout.Label(('Materials ' + Resources.FindObjectsOfTypeAll[of Material]().Length))
		GUILayout.Label(('GameObjects ' + Resources.FindObjectsOfTypeAll[of GameObject]().Length))
		GUILayout.Label(('Components ' + Resources.FindObjectsOfTypeAll[of Component]().Length))

import System.Collections.Generic;

// This script finds all the objects in scene, excluding prefabs: function GetAllObjectsInScene(): List.<GameObject> { var objectsInScene: List.<GameObject> = new List.<GameObject>(); for (var go: GameObject in Resources.FindObjectsOfTypeAll.<GameObject>()) { if (go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave) continue; var assetPath: String = AssetDatabase.GetAssetPath(go.transform.root.gameObject); if (!String.IsNullOrEmpty(assetPath)) continue; objectsInScene.Add(go); } return objectsInScene; }