# FindObjectsOfTypeAll

> Obtains all objects of type type.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.5/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

## FindObjectsOfTypeAll(Type)

Obtains all objects of type `type`.

```csharp
public static Object[] FindObjectsOfTypeAll(Type type)
```

### Parameters

**** (\[Type]\(https\://learn.microsoft.com/dotnet/api/system.type)): The type of object.

### Returns

| Type                                                                | Description                                         |
| ------------------------------------------------------------------- | --------------------------------------------------- |
| [Object\[\]](/engine/6000.5/script-reference/unityengine/object.md) | Returns any array of loaded objects of type `type`. |

### Remarks

This method uses non-generic types and can return any type of Unity object that is loaded, such as GameObjects, prefabs, materials, meshes, and textures. It also lists internal objects, so be careful how you handle the returned objects.

Unlike [Object.FindObjectsOfType](/engine/6000.5/script-reference/unityengine/object/findobjectsoftype.md) this method also lists disabled objects.

Note: This method is very slow. Avoid using it every frame.

The following code example finds all GameObjects in the scene using non-generic methods:

### Examples

```csharp
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;

public class ExampleScript : MonoBehaviour
{
    List<UnityEngine.Object> GetSceneObjectsNonGeneric()
    {
        List<UnityEngine.Object> objectsInScene = new List<UnityEngine.Object>();

        foreach (UnityEngine.Object go in Resources.FindObjectsOfTypeAll(typeof(UnityEngine.Object)) as UnityEngine.Object[])
        {
            GameObject cGO = go as GameObject;
            if (cGO != null && !EditorUtility.IsPersistent(cGO.transform.root.gameObject) && !(go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave))
                objectsInScene.Add(go);
        }

        return objectsInScene;
    }
}
```

## FindObjectsOfTypeAll\<T>()

Obtains a list of all objects of type `T`.

```csharp
public static T[] FindObjectsOfTypeAll<T>() where T : Object
```

### Returns

| Type              | Description                              |
| ----------------- | ---------------------------------------- |
| [\<T>\[\]](./.md) | A list of all objects of the given type. |

### Remarks

This method can return any type of Unity object that is loaded, such as GameObjects, prefabs, materials, meshes, and textures. It also lists internal objects, therefore be careful with the way you handle the returned objects.

Unlike `Object.FindObjectsOfType`, this method also lists disabled objects.

The following example returns all GameObjects in the scene, in List\\\<GameObject\\> format.

```csharp
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class ExampleScript : MonoBehaviour
{
    List<GameObject> GetAllObjectsOnlyInScene()
    {
        List<GameObject> objectsInScene = new List<GameObject>();

        foreach (GameObject go in Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[])
        {
            // EditorUtility.IsPersistent is true for objects saved to disk as assets (such as prefabs).
            // The leading ! keeps only in-scene objects and excludes those assets.
            if (!EditorUtility.IsPersistent(go.transform.root.gameObject) && !(go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave))
                objectsInScene.Add(go);
        }

        return objectsInScene;
    }
}
```

The following example returns all persistent GameObjects in a scene.

```csharp
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class ExampleScript : MonoBehaviour
{
    List<GameObject> GetNonSceneObjects()
    {
        List<GameObject> objectsInScene = new List<GameObject>();

        foreach (GameObject go in Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[])
        {
            // This is the same query as the previous example, but without the leading ! on IsPersistent.
            // It keeps only persistent GameObjects (assets such as prefabs) and excludes in-scene objects.
            if (EditorUtility.IsPersistent(go.transform.root.gameObject) && !(go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave))
                objectsInScene.Add(go);
        }

        return objectsInScene;
    }
}
```
