finding a tile in a tilemap from custom data

hello, I’m curious if I can use custom data to find a tile in a tilemap. for example, if the tile’s custom data for a name is “plant x,” can I search the tile atlas for a tile with that name via code, or do I need to do it manually through a for loop or a dictionary lookup?

The approach you use kind of depends on your use case. Can you tell me more about what you’re trying to do?

Let’s say you have this scenario:

  • a tilemap is filled with tiles. This is a mix of nature-themed and urban-themed tiles with different textures
  • A user can click on tiles to plant a “plant x” on that tile
  • The “plant x” data is applied to the clicked tile’s custom data
  • Next, I want to highlight all tiles that the user has planted this plant on

In this case, there isn’t any type of tile you can use to limit the search by texture/tile id. You could take two approaches:

  1. loop over every tile in the grid, get the custom data and check if it’s “plant x”
  2. when adding “plant x” to a tile’s custom data, save the tile’s coordinate to an array/dictionary. When I want to highlight all “plant x” tiles, loop over the array/dictionary and highlight all tiles in the tilemap that have the coordinates.