# FindFirstObjectByType

> Retrieves the first active loaded object of Type type.

## Definition

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

## FindFirstObjectByType\<T>()

Retrieves the first active loaded object of Type `type`.

> **Warning:**
>
> **Deprecated.** FindFirstObjectByType has been deprecated because it relies on instance ID ordering. Use FindAnyObjectByType instead, which does not depend on ordering.

```csharp
public static T FindFirstObjectByType<T>() where T : Object
```

### Returns

| Type | Description                                                                                                                    |
| ---- | ------------------------------------------------------------------------------------------------------------------------------ |
| T    | Returns the first active loaded object that matches the specified type. If no object matches the specified type, returns null. |

### Remarks

Object.FindFirstObjectByType doesn't return Assets (for example meshes, textures, or prefabs), or inactive objects. It also doesn't return objects that have [HideFlags.DontSave](/engine/6000.7/script-reference/unityengine/hideflags/dontsave.md) set.

**Note**: This function is very resource intensive. It's best practice to not use this function every frame and instead, in most cases, use the singleton pattern. Alternatively if you only need any instance of a matching object rather than the first one you can use the faster [Object.FindAnyObjectByType](/engine/6000.7/script-reference/unityengine/object/findanyobjectbytype.md)

See Also: [Object.FindAnyObjectByType](/engine/6000.7/script-reference/unityengine/object/findanyobjectbytype.md), [Object.FindObjectsByType](/engine/6000.7/script-reference/unityengine/object/findobjectsbytype.md).

### Examples

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

// Search for the first active TextMesh and first active or inactive CanvasRenderer.
// If found print the names, else print a message saying none were found.
public class ExampleClass : MonoBehaviour
{
    void Start()
    {
        TextMesh texture = (TextMesh)FindFirstObjectByType(typeof(TextMesh));
        if (texture)
            Debug.Log("TextMesh object found: " + texture.name);
        else
            Debug.Log("No TextMesh object could be found");
// Include inactive objects in search for CanvasRenderer
        CanvasRenderer canvas = FindFirstObjectByType<CanvasRenderer>(FindObjectsInactive.Include);
        if (canvas)
            Debug.Log("CanvasRenderer object found: " + canvas.name);
        else
            Debug.Log("No CanvasRenderer object could be found");
    }
}
```

## FindFirstObjectByType\<T>(FindObjectsInactive)

Retrieves the first active loaded object of Type `type`.

> **Warning:**
>
> **Deprecated.** FindFirstObjectByType has been deprecated because it relies on instance ID ordering. Use FindAnyObjectByType instead, which does not depend on ordering.

```csharp
public static T FindFirstObjectByType<T>(FindObjectsInactive findObjectsInactive) where T : Object
```

### Parameters

**** (\[FindObjectsInactive]\(/engine/6000.7/script-reference/unityengine/findobjectsinactive)): Whether to include components attached to inactive GameObjects. If you don't specify this parameter, this function doesn't include inactive objects in the results.

### Returns

| Type | Description                                                                                                                    |
| ---- | ------------------------------------------------------------------------------------------------------------------------------ |
| T    | Returns the first active loaded object that matches the specified type. If no object matches the specified type, returns null. |

### Remarks

Object.FindFirstObjectByType doesn't return Assets (for example meshes, textures, or prefabs), or inactive objects. It also doesn't return objects that have [HideFlags.DontSave](/engine/6000.7/script-reference/unityengine/hideflags/dontsave.md) set.

**Note**: This function is very resource intensive. It's best practice to not use this function every frame and instead, in most cases, use the singleton pattern. Alternatively if you only need any instance of a matching object rather than the first one you can use the faster [Object.FindAnyObjectByType](/engine/6000.7/script-reference/unityengine/object/findanyobjectbytype.md)

See Also: [Object.FindAnyObjectByType](/engine/6000.7/script-reference/unityengine/object/findanyobjectbytype.md), [Object.FindObjectsByType](/engine/6000.7/script-reference/unityengine/object/findobjectsbytype.md).

### Examples

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

// Search for the first active TextMesh and first active or inactive CanvasRenderer.
// If found print the names, else print a message saying none were found.
public class ExampleClass : MonoBehaviour
{
    void Start()
    {
        TextMesh texture = (TextMesh)FindFirstObjectByType(typeof(TextMesh));
        if (texture)
            Debug.Log("TextMesh object found: " + texture.name);
        else
            Debug.Log("No TextMesh object could be found");
// Include inactive objects in search for CanvasRenderer
        CanvasRenderer canvas = FindFirstObjectByType<CanvasRenderer>(FindObjectsInactive.Include);
        if (canvas)
            Debug.Log("CanvasRenderer object found: " + canvas.name);
        else
            Debug.Log("No CanvasRenderer object could be found");
    }
}
```

## FindFirstObjectByType(Type)

Retrieves the first active loaded object of Type `type`.

> **Warning:**
>
> **Deprecated.** FindFirstObjectByType has been deprecated because it relies on instance ID ordering. Use FindAnyObjectByType instead, which does not depend on ordering.

```csharp
public static Object FindFirstObjectByType(Type type)
```

### Parameters

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

### Returns

| Type                                                            | Description                                                                                                                    |
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| [Object](/engine/6000.7/script-reference/unityengine/object.md) | Returns the first active loaded object that matches the specified type. If no object matches the specified type, returns null. |

### Remarks

Object.FindFirstObjectByType doesn't return Assets (for example meshes, textures, or prefabs), or inactive objects. It also doesn't return objects that have [HideFlags.DontSave](/engine/6000.7/script-reference/unityengine/hideflags/dontsave.md) set.

**Note**: This function is very resource intensive. It's best practice to not use this function every frame and instead, in most cases, use the singleton pattern. Alternatively if you only need any instance of a matching object rather than the first one you can use the faster [Object.FindAnyObjectByType](/engine/6000.7/script-reference/unityengine/object/findanyobjectbytype.md)

See Also: [Object.FindAnyObjectByType](/engine/6000.7/script-reference/unityengine/object/findanyobjectbytype.md), [Object.FindObjectsByType](/engine/6000.7/script-reference/unityengine/object/findobjectsbytype.md).

### Examples

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

// Search for the first active TextMesh and first active or inactive CanvasRenderer.
// If found print the names, else print a message saying none were found.
public class ExampleClass : MonoBehaviour
{
    void Start()
    {
        TextMesh texture = (TextMesh)FindFirstObjectByType(typeof(TextMesh));
        if (texture)
            Debug.Log("TextMesh object found: " + texture.name);
        else
            Debug.Log("No TextMesh object could be found");
// Include inactive objects in search for CanvasRenderer
        CanvasRenderer canvas = FindFirstObjectByType<CanvasRenderer>(FindObjectsInactive.Include);
        if (canvas)
            Debug.Log("CanvasRenderer object found: " + canvas.name);
        else
            Debug.Log("No CanvasRenderer object could be found");
    }
}
```

## FindFirstObjectByType(Type, FindObjectsInactive)

Retrieves the first active loaded object of Type `type`.

> **Warning:**
>
> **Deprecated.** FindFirstObjectByType has been deprecated because it relies on instance ID ordering. Use FindAnyObjectByType instead, which does not depend on ordering.

```csharp
public static Object FindFirstObjectByType(Type type, FindObjectsInactive findObjectsInactive)
```

### Parameters

**** (\[Type]\(https\://learn.microsoft.com/dotnet/api/system.type)): The type of object to find.**** (\[FindObjectsInactive]\(/engine/6000.7/script-reference/unityengine/findobjectsinactive)): Whether to include components attached to inactive GameObjects. If you don't specify this parameter, this function doesn't include inactive objects in the results.

### Returns

| Type                                                            | Description                                                                                                                    |
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| [Object](/engine/6000.7/script-reference/unityengine/object.md) | Returns the first active loaded object that matches the specified type. If no object matches the specified type, returns null. |

### Remarks

Object.FindFirstObjectByType doesn't return Assets (for example meshes, textures, or prefabs), or inactive objects. It also doesn't return objects that have [HideFlags.DontSave](/engine/6000.7/script-reference/unityengine/hideflags/dontsave.md) set.

**Note**: This function is very resource intensive. It's best practice to not use this function every frame and instead, in most cases, use the singleton pattern. Alternatively if you only need any instance of a matching object rather than the first one you can use the faster [Object.FindAnyObjectByType](/engine/6000.7/script-reference/unityengine/object/findanyobjectbytype.md)

See Also: [Object.FindAnyObjectByType](/engine/6000.7/script-reference/unityengine/object/findanyobjectbytype.md), [Object.FindObjectsByType](/engine/6000.7/script-reference/unityengine/object/findobjectsbytype.md).

### Examples

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

// Search for the first active TextMesh and first active or inactive CanvasRenderer.
// If found print the names, else print a message saying none were found.
public class ExampleClass : MonoBehaviour
{
    void Start()
    {
        TextMesh texture = (TextMesh)FindFirstObjectByType(typeof(TextMesh));
        if (texture)
            Debug.Log("TextMesh object found: " + texture.name);
        else
            Debug.Log("No TextMesh object could be found");
// Include inactive objects in search for CanvasRenderer
        CanvasRenderer canvas = FindFirstObjectByType<CanvasRenderer>(FindObjectsInactive.Include);
        if (canvas)
            Debug.Log("CanvasRenderer object found: " + canvas.name);
        else
            Debug.Log("No CanvasRenderer object could be found");
    }
}
```
