Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetUsedTiles

Returns a Tilemap.TileArray containing the unique Tile instances used in this Tilemap. The array is allocated using the given Allocator.
Read time 2 minutesLast updated 6 days ago

Definition

GetUsedTiles(Allocator)

Returns a Tilemap.TileArray containing the unique Tile instances used in this Tilemap. The array is allocated using the given Allocator.
public Tilemap.TileArray GetUsedTiles(Allocator allocator = Allocator.Temp)

Parameters

allocator

The allocator type used to allocate the memory for the Tilemap.SpriteArray. The default value is Allocator.Temp.

Returns

Type

Description

TileArrayA Tilemap.TileArray containing the all unique Tile instances used in the Tilemap.

Remarks

Examples

// Retrieves all used Tiles from a Tilemap and prints out the Tile names to consoleusing 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 allocated by the given
MemoryLabel
with the unique Tiles used in the Tilemap.
public Tilemap.TileArray GetUsedTiles(MemoryLabel memoryLabel)

Parameters

memoryLabel

Memory label used for profiling and tracking this memory allocation in Unity.

Returns

Type

Description

TileArrayTilemap.TileArray containing the unique Tiles used in the Tilemap.

Examples

// Retrieves all used Tiles from a Tilemap and prints out the Tile names to consoleusing 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); } }}