Legacy Documentation: Version 5.5
LanguageEnglish
  • C#
  • JS

Script language

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

Resources.FindObjectsOfTypeAll

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

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

Parameters

type Type 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.

#pragma strict
public class ExampleScript extends MonoBehaviour {
	// the first step. You could then print the names of all leaked assets of that type.
	function Start() {
		print("All " + Resources.FindObjectsOfTypeAll(UnityEngine.Object).Length);
		print("Textures " + Resources.FindObjectsOfTypeAll(Texture).Length);
		print("AudioClips " + Resources.FindObjectsOfTypeAll(AudioClip).Length);
		print("Meshes " + Resources.FindObjectsOfTypeAll(Mesh).Length);
		print("Materials " + Resources.FindObjectsOfTypeAll(Material).Length);
		print("GameObjects " + Resources.FindObjectsOfTypeAll(GameObject).Length);
		print("Components " + Resources.FindObjectsOfTypeAll(Component).Length);
	}
}
using UnityEngine;
using System.Collections;

public class ExampleScript : MonoBehaviour { // 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.

void Start() { print("All " + Resources.FindObjectsOfTypeAll(typeof(UnityEngine.Object)).Length); print("Textures " + Resources.FindObjectsOfTypeAll(typeof(Texture)).Length); print("AudioClips " + Resources.FindObjectsOfTypeAll(typeof(AudioClip)).Length); print("Meshes " + Resources.FindObjectsOfTypeAll(typeof(Mesh)).Length); print("Materials " + Resources.FindObjectsOfTypeAll(typeof(Material)).Length); print("GameObjects " + Resources.FindObjectsOfTypeAll(typeof(GameObject)).Length); print("Components " + Resources.FindObjectsOfTypeAll(typeof(Component)).Length); } }
#pragma strict
public class ExampleScript extends MonoBehaviour {
	// This script finds all the objects in scene, excluding prefabs:
	function GetAllObjectsInScene() {
		var objectsInScene: List.<GameObject> = new List.<GameObject>();
		for (var go: GameObject in Resources.FindObjectsOfTypeAll(GameObject) as GameObject[]) {
			if (go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave)if (!EditorUtility.IsPersistent(go.transform.root.gameObject))objectsInScene.Add(go);
		}
		return objectsInScene;
	}
}
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;

public class ExampleScript : MonoBehaviour { // This script finds all the objects in scene, excluding prefabs:

List<GameObject> GetAllObjectsInScene() { List<GameObject> objectsInScene = new List<GameObject>();

foreach (GameObject go in Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[]) { if (go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave) continue;

if (!EditorUtility.IsPersistent(go.transform.root.gameObject)) continue;

objectsInScene.Add(go); }

return objectsInScene; } }

public static function FindObjectsOfTypeAll(): T[];
public static T[] FindObjectsOfTypeAll();

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.

#pragma strict
public class ExampleScript extends MonoBehaviour {
	// the first step. You could then print the names  of all leaked assets of that type.
	function Start() {
		print("All " + Resources.FindObjectsOfTypeAll.<UnityEngine.Object>().Length);
		print("Textures " + Resources.FindObjectsOfTypeAll.<Texture>().Length);
		print("AudioClips " + Resources.FindObjectsOfTypeAll.<AudioClip>().Length);
		print("Meshes " + Resources.FindObjectsOfTypeAll.<Mesh>().Length);
		print("Materials " + Resources.FindObjectsOfTypeAll.<Material>().Length);
		print("GameObjects " + Resources.FindObjectsOfTypeAll.<GameObject>().Length);
		print("Components " + Resources.FindObjectsOfTypeAll.<Component>().Length);
	}
}
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;

public class ExampleScript : MonoBehaviour { // 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.

void Start() { print("All " + Resources.FindObjectsOfTypeAll<UnityEngine.Object> ().Length); print("Textures " + Resources.FindObjectsOfTypeAll<Texture> ().Length); print("AudioClips " + Resources.FindObjectsOfTypeAll<AudioClip> ().Length); print("Meshes " + Resources.FindObjectsOfTypeAll<Mesh> ().Length); print("Materials " + Resources.FindObjectsOfTypeAll<Material> ().Length); print("GameObjects " + Resources.FindObjectsOfTypeAll<GameObject> ().Length); print("Components " + Resources.FindObjectsOfTypeAll<Component> ().Length); } }
#pragma strict
public class ExampleScript extends MonoBehaviour {
	// This script finds all the objects in scene, excluding prefabs:
	function GetAllObjectsInScene() {
		var objectsInScene: List.<GameObject> = new List.<GameObject>();
		for (var go: GameObject in Resources.FindObjectsOfTypeAll(GameObject) as GameObject[]) {
			if (go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave)if (!EditorUtility.IsPersistent(go.transform.root.gameObject))objectsInScene.Add(go);
		}
		return objectsInScene;
	}
}
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;

public class ExampleScript : MonoBehaviour { // This script finds all the objects in scene, excluding prefabs:

List<GameObject> GetAllObjectsInScene() { List<GameObject> objectsInScene = new List<GameObject>();

foreach (GameObject go in Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[]) { if (go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave) continue;

if (!EditorUtility.IsPersistent(go.transform.root.gameObject)) continue;

objectsInScene.Add(go); }

return objectsInScene; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961