TileMap get_used_cells not updating when Scene tile is moved

Godot Version

4.2

Question

I’d like to use a TileMap to track enemy locations.

I can dynamically spawn Enemy Scenes by using TileMap.set_tile().

After I do, I can call TileMap.get_used_cells(), and it properly lists the cells where the Enemy Scenes were spawned.

However, the problem is that when I move the Enemy Scene via it’s position property, it becomes desynced from the TileMaps get_used_cells.

For instance, if the Enemy was spawned at (0,0), and I moved it to (0,1), TileMap.get_used_cells still returns (0,0). I’ve tried calling update_internals, but no luck.

So, my question is, is there a way to move the Scene Tile so that it stays in sync with the TileMap used_cells?

Thanks in advance!

If you really want to use a TileMap for this (which I don’t recommend), then you need to call TileMap.set_tile twice each time an enemy moves: once to erase it from its previous position and once to set it to its new position.