GetUsedSprites
Returns a Tilemap.SpriteArray containing the unique Sprite instances used in the Tilemap. The array is allocated using the given Allocator.
Read time 2 minutesLast updated 5 days ago
Definition
- Type: Method
- Namespace: UnityEngine.Tilemaps
- Assembly: UnityEngine.TilemapModule
GetUsedSprites(Allocator)
Returns a Tilemap.SpriteArray containing the unique Sprite instances used in the Tilemap. The array is allocated using the given Allocator.
public Tilemap.SpriteArray GetUsedSprites(Allocator allocator = Allocator.Temp)
Parameters
The allocator type used to allocate the memory for the Tilemap.SpriteArray. The default value is Allocator.Temp.
Returns
Type | Description |
|---|---|
| SpriteArray | A Tilemap.SpriteArray containing the all unique Sprite assets used in the Tilemap. |
Remarks
The Allocator must be either Allocator.Temp or Allocator.Persistent.
Examples
// Retrieves all used Sprites from a Tilemap and prints out the Sprite names to consoleusing UnityEngine;using UnityEngine.Tilemaps;public class TilemapExample1 : MonoBehaviour{ void Start() { Tilemap tilemap = GetComponent<Tilemap>(); using var usedSprites = tilemap.GetUsedSprites(); // Will call SpriteArray.Dispose() once it is out of scope foreach (var sprite in usedSprites) { print(sprite.name); } }}
GetUsedSprites(MemoryLabel)
Returns a Tilemap.SpriteArray containing the unique Sprite instances used in the Tilemap. The array is allocated using the given Allocator.
public Tilemap.SpriteArray GetUsedSprites(MemoryLabel memoryLabel)
Parameters
Memory label used for profiling and tracking this memory allocation in Unity.
Returns
Type | Description |
|---|---|
| SpriteArray | A Tilemap.SpriteArray containing the all unique Sprite assets used in the Tilemap. |
Examples
// Retrieves all used Sprites from a Tilemap and prints out the Sprite 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 usedSprites = tilemap.GetUsedSprites(kMemoryLabel); // Will call SpriteArray.Dispose() once it is out of scope foreach (var sprite in usedSprites) { print(sprite.name); } }}