Advanced tilemap rendering

Hey. I want to be able to create some special effects for my tilemaps that would require a more sophisticated solution than drawing a sprite/animated sprite.

For example, I want to make water tiles that have their own material that takes multiple maps. One way to achieve that would be to spawn game objects through tiles with a sprite renderer that has the corresponding material. Unfortunately Game Objects don’t scale well in large numbers, and spawning thousands of them can really hurt the performance of the game.
I thought about maybe finding a way to edit the tilemap’s mesh properties through code, but I haven’t figured if that’s even possible.

Is there a way to do what I’m trying to achieve with Unity tilemaps?

Create a new Tilemap for Water and give it its own Material under the same Grid. You can check out the Robodash demo for an example. 2d-gamedemo-robodash/Assets at master · Unity-Technologies/2d-gamedemo-robodash · GitHub

But would I be able to set individual material properties per tile?

No, a GameObject with SpriteRenderer is more appropriate for that. A Tilemap is paired with a single TilemapRenderer which accepts just one material. You could also pursue a mixed strategy: if the special effect is temporary you could instantiate a GameObject that will perform whatever it is you want to do to your water. This would save you from needing a SpriteRenderer for each water tile, but allow you to, for example, animate a splash. It’s hard to say without more details about what you aim to do.

I’m really just looking for a way to use the tile system but have the flexibility of using a material per tile. While I could spawn a game object with a sprite renderer it will scale poorly performance wise.

You might be able to use a lower-level API to achieve what you want. You might be able to use multiple Tilemaps each with their own material (a Water tilemap, a Ground tilemap, a Tree tilemap, etc). You may be able to mix SpriteRenderers and Tilemaps together so that you can avoid GameObjects most of the time but change materials around easily per-entity with a SpriteRenderer. There is no way to use a unique material per tile while using Unity Tilemaps.

Thought so. Thanks for the help.
I’ll see if I can build my own Tilemap renderer that would be able to go over my custom tiles and use their data to update the mesh accordingly.