Version: Unity 6.4 Alpha (6000.4)
LanguageEnglish
  • C#

Tilemap.GetUsedSprites

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public Tilemaps.Tilemap.SpriteArray GetUsedSprites(Unity.Collections.Allocator allocator);

Parameters

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

Returns

SpriteArray A SpriteArray containing the all unique Sprite assets used in the Tilemap.

Description

Returns a SpriteArray containing the unique Sprite instances used in the Tilemap. The array is allocated using the given Allocator.

The Allocator must be either Allocator.Temp or Allocator.Persistent.

// Retrieves all used Sprites from a Tilemap and prints out the Sprite names to console
using 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); } } }

Declaration

public Tilemaps.Tilemap.SpriteArray GetUsedSprites(Unity.Collections.MemoryLabel memoryLabel);

Parameters

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

Returns

SpriteArray A SpriteArray containing the all unique Sprite assets used in the Tilemap.

Description

Returns a SpriteArray containing the unique Sprite instances used in the Tilemap. The array is allocated using the given Allocator.

// Retrieves all used Sprites from a Tilemap and prints out the Sprite 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 usedSprites = tilemap.GetUsedSprites(kMemoryLabel); // Will call SpriteArray.Dispose() once it is out of scope foreach (var sprite in usedSprites) { print(sprite.name); } } }