| Parameter | Description |
|---|---|
| bounds | The bounds to retrieve from. |
| allocator | The Allocator type used to allocate the memory for the TileArray. You must use Allocator.Temp, Allocator.Domain, or Allocator.Persistent. The default value is Allocator.Temp. |
Retrieves all tiles within the given bounds as a TileArray .
Use this method to efficiently retrieve tiles as a batch, rather than calling GetTile for each position. This can significantly reduce overhead when processing large areas.
// Retrieves all Tiles from an area on the Tilemap and prints out the Tiles to console using UnityEngine; using UnityEngine.Tilemaps;
public class TilemapExample1 : MonoBehaviour { public BoundsInt area;
void GetTilesExample1() { Tilemap tilemap = GetComponent<Tilemap>(); using var tiles = tilemap.GetTiles(area); // Will call TileArray.Dispose() once it is out of scope foreach (var tile in tiles) { print(tile != null ? tile.name : "Empty"); } } }
| Parameter | Description |
|---|---|
| bounds | The bounds to retrieve from. |
| memoryLabel | Memory label used for profiling and tracking this memory allocation in Unity. |
Retrieves a TileArray within the given bounds.
This is meant for more a performant way to get Tiles as a batch, when compared to calling GetTile for every single position.
// Retrieves all Tiles from an area on the Tilemap and prints out the Tiles to console using Unity.Collections; using UnityEngine; using UnityEngine.Tilemaps;
public class TilemapExample2 : MonoBehaviour { static readonly MemoryLabel kMemoryLabel = new MemoryLabel("TilemapExample", "Get", Allocator.Domain);
public BoundsInt area;
void GetTilesExample2() { Tilemap tilemap = GetComponent<Tilemap>(); using var tiles = tilemap.GetTiles(area, kMemoryLabel); // Will call TileArray.Dispose() once it is out of scope foreach (var tile in tiles) { print(tile != null ? tile.name : "Empty"); } } }
| Parameter | Description |
|---|---|
| bounds | The bounds to retrieve from. |
| positions | A PositionArray containing the position of each TileBase in the bounds. |
| tiles | A TileArray containing all the TileBase instances in the bounds. |
| allocator | The Allocator type used to allocate the memory for the TileArray. You must use Allocator.Temp, Allocator.Domain, or Allocator.Persistent. The default value is Allocator.Temp. |
| withinBounds | Whether to retrieve the tiles within the given bounds. The default value is True. If True, only tiles located within the tilemap’s defined bounds are returned. If False, tiles outside the tilemap’s bounds may also be returned if they fall within the given bounds. |
int Returns the number of positions and Tiles retrieved.
Retrieves all tiles within the given bounds as a TileArray, with their corresponding positions in a PositionArray. Only positions containing a Tile are included.
Use this method to efficiently retrieve tiles as a batch, rather than calling GetTile for each position. This can significantly reduce overhead when processing large areas.
// Retrieves all Tiles from an area on the Tilemap and prints out the Tiles to console using UnityEngine; using UnityEngine.Tilemaps;
public class TilemapExample3 : MonoBehaviour { public BoundsInt area = new BoundsInt(0, 0, 0, 5, 5, 1);
void GetTilesExample3() { Tilemap tilemap = GetComponent<Tilemap>(); var count = tilemap.GetTiles(area, out var positions, out var tiles); for (var i = 0; i < count; i++) { print($"Position: {positions[i]}, Tile: {tiles[i].name}"); } // Manually dispose allocated arrays positions.Dispose(); tiles.Dispose(); } }
If withinBounds is set to True, this returns all tiles within (0, 0, 0) to (5, 5, 1), where x and y are between 0 and 5. If withinBounds is set to False, tiles outside the Tilemap's bounds might be included if they fall within the given bounds. Positions such as (6, 0, 0), (-1, 1, 0), or (-4, 5, 0) are included, but positions such as (-2, 0, 0) or (6, 6, 0) are excluded because they either come before the start of the given bounds or after the end of the given bounds.
| Parameter | Description |
|---|---|
| bounds | The bounds to retrieve from. |
| positions | A PositionArray containing the position of each TileBase in the bounds. |
| tiles | A TileArray containing all the TileBase instances in the bounds. |
| memoryLabel | Memory label used for profiling and tracking this memory allocation in Unity. |
| withinBounds | Whether to retrieve the tiles within the given bounds. The default value is True. |
int Returns the number of positions and Tiles retrieved.
Retrieves all tiles within the given bounds as a TileArray, with their corresponding positions in a PositionArray. Only positions containing a Tile are included.
Use this method to efficiently retrieve tiles as a batch, rather than calling GetTile for each position. This can significantly reduce overhead when processing large areas.
// Retrieves all Tiles from an area on the Tilemap and prints out the Tiles to console using Unity.Collections; using UnityEngine; using UnityEngine.Tilemaps;
public class TilemapExample4 : MonoBehaviour { static readonly MemoryLabel kMemoryLabel = new MemoryLabel("TilemapExample", "Get", Allocator.Domain);
public BoundsInt area = new BoundsInt(0, 0, 0, 5, 5, 1);
void GetTilesExample4() { Tilemap tilemap = GetComponent<Tilemap>(); var count = tilemap.GetTiles(area, out var positions, out var tiles, kMemoryLabel); for (var i = 0; i < count; i++) { print($"Position: {positions[i]}, Tile: {tiles[i].name}"); } // Manually dispose allocated arrays positions.Dispose(); tiles.Dispose(); } }