Unity TileMap Bug

I’ve run across a mildly infuriating issue that I finally resolved. If you look carefully at the roof of the windmill in my level selector, you’ll notice that it disappears when I scroll up and reappears when I scroll down.

I’ve done many a Google / StackOverflow / UnityForum searches to no avail and it wasn’t clear to me how to solve the problem. I originally though it was an issue with me using a ScrollRect with a TileMap, but I took the content out of the ScrollRect, manually moved the camera to still see the same artifact.

It seems the actual problem is the hidden bounding box/size of the TileMap. In the inspector view of the TileMap, you’ll see no properties allowing you to see or change the size.

However, I was finally able to identify the actual problem by sheer luck. I randomly inserted another object further from the original tile that I had drawn, delete that same new object and retested the scene. With that, the tile somehow correctly persisted and displayed.

Looking at the source diff in version control I then saw the hidden delta in the actual scene file. It turns out that the TileMaps have a size property, so when I added and deleted the test object, it changed the size to accommodate the tile that I added.

Tilemap:
  ...
  m_Tiles:
	... tile details ...
  ... more Tilemap properties ...
  // Here's the magic
  m_Size: {x: 1, y: 10, z: 1}
  // Above!
  ... even more Tilemap properties

Before I added and deleted the random object, the m_Size property was {x: 1, y: 1, z: 1}, notice now it’s {x: 1, y: 10, z:1}

My guess is that Unity has some definition of the TileMap size to be efficient about only rendering what’s on screen. I eventually report the issue, but I have a workaround for now. I hope this helps someone else chasing the same issue of disappearing tiles in TileMaps!


Posted

in

by

Tags:

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.