Version: Unity 7.0 Alpha (7000.0)
LanguageEnglish
  • C#

Tilemap.tilemapTilesChanged

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

Description

Callback when Tiles on a Tilemap have changed, without allocating.

This returns the cells which have been updated and why. The cells are only valid for the duration of the callback.

 // Log the cells which have changed, ignoring changes which cannot affect collision
using Unity.Collections;
using UnityEngine;
using UnityEngine.Tilemaps;

public class ExampleClass : MonoBehaviour { void OnEnable() { Tilemap.tilemapTilesChanged += OnTilesChanged; }

void OnDisable() { Tilemap.tilemapTilesChanged -= OnTilesChanged; }

void OnTilesChanged(Tilemap tilemap, NativeArray<Tilemap.SyncTile> entries, TileChangeReason reason) { if ((reason & TileChangeReason.Physics) == 0) return;

for (var i = 0; i < entries.Length; ++i) { var entry = entries[i]; Debug.Log(entry.hasTile ? $"{entry.position} has a Tile" : $"{entry.position} is empty"); } } }