How do I use my own MapTile class for a TileMap?
I've made my own simple MapTile class. So far all it contains is an integer for how expensive that tile is to walk across. I would now like to use that in the Tile Palette or just be able to spawn the tiles dynamically.
I've tried dragging my class into the Tile Palette, which seems to "work" in that the relevant tile in the palette now has that class, but I can no longer set a sprite for the tile (selected tile is the one out left with the red outline):
I've also tried to dynamically spawn the tiles, which also "works", but since the tiles don't have any sprites they are invisible (but they do exist)...
How is one supposed to use ones own MapTile classes with the TileMap and the Tile Palette?
Answer by SvendDino · Jun 22, 2021 at 09:06 PM
Turns out I just had to override GetTileData
in my custom Map Tile class (overriding TileBase
) to get it to work, and set the sprite and colour in that method.
This is the method I've added:
public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
{
base.GetTileData(position, tilemap, ref tileData);
tileData.flags = TileFlags.LockColor;
tileData.sprite = _sprite;
Color c = color;
tileData.color = c;
}
Your answer
Follow this Question
Related Questions
Tile Palette not showing new Tiles 0 Answers
What is causing this issue with Tilemap.SetTile and Update method? 0 Answers
[SEND HELP] Troubleshooting 2D Animated Tile Problem. 0 Answers
Tilemap, unique tiles. 1 Answer
Applying Normal Maps to Random Tiles 0 Answers