Tiles appearing and dissapearing when player walks over the tilemap

Hi fellow Unity programmers!

I have two tilemaps, one is filled with procedurally generated land tiles and second one overlapping the first one, which is used for tiles like trees and stones. Side note: this issue happens no matter if I use just one tilemap with two layers (z coord being 0 and 1) or if I use two different tilemaps overlapping each other. The issue I am facing is that when I move the camera at certain locations, some of the tiles of the second tilemap (or the second tilemap layer) dissapear and appear back based on the camera location. I include a gif of what is happening there for better understanding.

It seems to be a problem of chunk tilemap renderer mode.
My question is, how to overcome such a bug?

I tried using different sorting layers on the two tilemaps. I tried to mess with the tilemap renderer chunk culling bounds but I only ended up with weak performance and never really fixed the issue. What seems to fix the issue is to change the renderer mode to individual tile instead of chunk, but then drawing tiles on the second tilemap (or tilemap layer) is messed up and only some tile positions are allowed to be drawn onto.

Any insight into the problem is welcomed! Feel free to ask for any additional relevant information.
Thanks for your replies in advance.

8384142--1105710--dissapearing-tiles.gif

Hi, do the Sprites used in your Tilemap belong to the same Texture? If not, you could try atlassing all the Sprites used into a single Sprite Atlas (some details at Unity - Manual: Tilemap Renderer Modes).

If you are using two different Tilemaps overlapping each other, you should have both of the TilemapRenderers have different Sorting Layers and Orders so that they will overlap properly.

Let us know if that helps!

No, my Sprites are saved individually. Unfortunatelly using the SpriteAtlas and different sorting layers and order for the two tilemaps did not help. I created the SpriteAtlas before running the game and changed the layers and order while in runtime. Could this be an issue? I create the tilemaps programatically, so they are not available in the editor before the runtime.

I tried also this piece of code creating the tilemaps manually (with layering and ordering done as I would in the editor):

Photographs of code are not a thing. If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

If you do it incorrectly it will be. But that’s where Unity makes it SUPER easy to check your work: run your game, see the issue, then press PAUSE and go digging into the scene. Are all the layers and cameras and sorting and everything as you expect? They probably won’t be.

It may also be helpful to make an ultra-tiny level that shows off the problem and use that for testing / debugging.

Your gif above certainly looks like a sorting problem, so I would start there. here’s some more notes:

Three (3) ways that Unity draws / stacks / sorts / layers / overlays stuff:

https://discussions.unity.com/t/841904/2

In short,

  1. The default 3D Renderers draw stuff according to Z depth - distance from camera.

  2. SpriteRenderers draw according to their Sorting Layer and Sorting Depth properties

  3. UI Canvas Renderers draw in linear transform sequence, like a stack of papers

If you find that you need to mix and match items using these different ways of rendering, and have them appear in ways they are not initially designed for, you need to:

  • identify what you are using
  • search online for the combination of things you are doing and how to to achieve what you want.

There may be more than one solution to try.

Additional reading in the official docs:

https://docs.unity3d.com/Manual/2DSorting.html

And SortingGroups can also be extremely helpful in certain circumstances:

https://docs.unity3d.com/Manual/class-SortingGroup.html

I don’t think that creating the Tilemaps and changing the sorting layers and order in runtime would be an issue.

If possible, could you file a bug with your project using the Unity Bug Reporter and post the case number here? We will check it out, thanks!

It seems that I have finally achieved desired behavior with combination of the individual tilemap renderer mode and using different sorting layers on the tilemaps at the same time. However, with the chunk tilemap renderer mode it is still an issue. I meanwhile reworked the project, so it is not possible for me to file a bug at the moment. I can however setup a demo project just for reporting the bug, when I have some spare time. I will then post the case number here. Thanks guys!

1 Like

Ok, as my time is always a spare time :), I have done it straight away, in the end.
Here is the incident number: IN-17576.
Thanks!

Thank you, we will check it out!

Just to update, this is a bug and we will work on this issue.

Could you share the version of Unity you are using? Thanks!

Hi, I am using Unity v. 2021.3.6f1.