# GetUsedTiles

> Returns a Tilemap.TileArray containing the unique Tile instances used in this Tilemap. The array is allocated using the given Allocator.

## Definition

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

## GetUsedTiles(Allocator)

Returns a [Tilemap.TileArray](/engine/6000.5/script-reference/unityengine/tilemaps/tilemap/tilearray.md) containing the unique [Tile](/engine/6000.5/script-reference/unityengine/wsa/tile.md) instances used in this [Tilemap](/engine/6000.5/script-reference/unityengine/tilemaps/tilemap.md). The array is allocated using the given Allocator.

```csharp
public Tilemap.TileArray GetUsedTiles(Allocator allocator = Allocator.Temp)
```

### Parameters

**** (\[Allocator]\(/engine/6000.5/script-reference/unity/collections/allocator)): The allocator type used to allocate the memory for the [Tilemap.SpriteArray](/engine/6000.5/script-reference/unityengine/tilemaps/tilemap/spritearray.md). The default value is [Allocator.Temp](/engine/6000.5/script-reference/unity/collections/allocator/temp.md).

### Returns

| Type                                                                                   | Description                                                                                                                                                                                                                                                                                  |
| -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [TileArray](/engine/6000.5/script-reference/unityengine/tilemaps/tilemap/tilearray.md) | A [Tilemap.TileArray](/engine/6000.5/script-reference/unityengine/tilemaps/tilemap/tilearray.md) containing the all unique [Tile](/engine/6000.5/script-reference/unityengine/wsa/tile.md) instances used in the [Tilemap](/engine/6000.5/script-reference/unityengine/tilemaps/tilemap.md). |

### Remarks

The [Allocator](/engine/6000.5/script-reference/unity/collections/allocator.md) must be either [Allocator.Temp](/engine/6000.5/script-reference/unity/collections/allocator/temp.md), [Allocator.Domain](/engine/6000.5/script-reference/unity/collections/allocator/domain.md) or [Allocator.Persistent](/engine/6000.5/script-reference/unity/collections/allocator/persistent.md).

### Examples

```csharp
// Retrieves all used Tiles from a Tilemap and prints out the Tile names to console
using UnityEngine;
using UnityEngine.Tilemaps;

public class TilemapExample1 : MonoBehaviour
{
    void Start()
    {
        Tilemap tilemap = GetComponent<Tilemap>();
        using var usedTiles = tilemap.GetUsedTiles(); // Will call TileArray.Dispose() once it is out of scope
        foreach (var tile in usedTiles)
        {
            print(tile.name);
        }
    }
}
```

## GetUsedTiles(MemoryLabel)

Returns a [Tilemap.TileArray](/engine/6000.5/script-reference/unityengine/tilemaps/tilemap/tilearray.md) allocated by the given `MemoryLabel` with the unique [Tile](/engine/6000.5/script-reference/unityengine/wsa/tile.md)s used in the [Tilemap](/engine/6000.5/script-reference/unityengine/tilemaps/tilemap.md).

```csharp
public Tilemap.TileArray GetUsedTiles(MemoryLabel memoryLabel)
```

### Parameters

**** (\[MemoryLabel]\(/engine/6000.5/script-reference/unity/collections/memorylabel)): Memory label used for profiling and tracking this memory allocation in Unity.

### Returns

| Type                                                                                   | Description                                                                                                                                                                                                                                                                   |
| -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [TileArray](/engine/6000.5/script-reference/unityengine/tilemaps/tilemap/tilearray.md) | [Tilemap.TileArray](/engine/6000.5/script-reference/unityengine/tilemaps/tilemap/tilearray.md) containing the unique [Tile](/engine/6000.5/script-reference/unityengine/wsa/tile.md)s used in the [Tilemap](/engine/6000.5/script-reference/unityengine/tilemaps/tilemap.md). |

### Examples

```csharp
// Retrieves all used Tiles from a Tilemap and prints out the Tile names to console
using Unity.Collections;
using UnityEngine;
using UnityEngine.Tilemaps;

public class TilemapExample2 : MonoBehaviour
{
    static readonly MemoryLabel kMemoryLabel = new MemoryLabel("TilemapExample", "Get", Allocator.Domain);

    void Start()
    {
        Tilemap tilemap = GetComponent<Tilemap>();
        using var usedTiles = tilemap.GetUsedTiles(kMemoryLabel); // Will call TileArray.Dispose() once it is out of scope
        foreach (var tile in usedTiles)
        {
            print(tile.name);
        }
    }
}
```
