2
\$\begingroup\$

In the newly added Tilemap system, the TileBase and Tile have no tag attribute and it is then not possible to identify them by anything else than their name attribute which is not very practical. It is however said in the documentation of TileBase :

Inherit from this to implement your custom tile to be placed in a Tilemap component.

I guess it can be used to create our own tile system but then I can't find a way to use this new class in the tilemap instead of the basic Tile class. How can I use this inheritance to create my own Tiles ?

\$\endgroup\$
2
\$\begingroup\$

Tiles only have one instance, you can get these from the tile palette. The tiles inside the tile maps are the same, so if you have a tile instance, you can simply use

tilemap.GetTile(position) == tile

To create your own tiles, you need to inherit from TileBase and override some of the methods (at least GetTileData and RefreshTile, the latter one should also refresh the surrounding tiles if necessary)

\$\endgroup\$
3
  • \$\begingroup\$ Oh okay each tile has only one instance. I have 4 different types of tiles, let's I want to give each tile an ID (as a string), let's say "Lava", "Water", "Sand" and "Forest". How can I do that because I don't create the tiles myself, they are created when I paint them on the grid. \$\endgroup\$ – Shashimee Nov 16 '17 at 3:18
  • \$\begingroup\$ @Shashimee You can very easily create a custom tile with a tag attribute \$\endgroup\$ – Bálint Nov 16 '17 at 9:45
  • \$\begingroup\$ For some examples of custom tiles, check out the repo github.com/Unity-Technologies/2d-extras/tree/master/Assets/… \$\endgroup\$ – Stephan Nov 16 '17 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.