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"); } } }