Question regarding TileMap Performance

I’m working on a large scale procedural world, and am currently using Unity’s TileMap system to render it. The world is currently (500 x 16) x (500 x 16) tiles large, but I render it in 16x16 tile chunks, with maybe 4-6 chunks on screen at a given time. I only regenerate chunks that are not already rendered, and I only check if the camera moves.

There are a few things popping up in the editor I can not find information about. One of them is during ChunkGeneration, namely the Tilemap.HasSyncTileCallback() function. This is generating a large amount of garbage, and I have no idea what it does, or if I can disable it.

The other function call is also concerning since it seems to increase the more I render tiles. This is named in the profiler as TilemapRenderer.CameraBoundsCheck → WaitForJobGroupID → TilemapRenderer.CameraBoundsJob. Note that I am not changing the camera bounds or anything.

I cannot find any guidelines concerning Tilemap do’s and don’ts in regards to performance. Should I be changing the origin of the tilemap whenever I render? I assume rendering tiles far from the origin costs more performance, but there is no documentation to be found.

Any help is appreciated.

Update 1:

The abovementioned CameraBoundsCheck bottleneck has to do with how large TileMap.Size is, setting it to a very large size will make the function take an insane amount of time.

So the ideal solution would be to set the TileMap’s Origin to the bottom left tile of the chunk I am rendering, and the size to the size of all rendered chunks combined.

TileMap.Size and TileMap.Origin minimum and maximum values seem to be changed whenever a new tile is placed outside of the current Origin and Size.

However, settings these values manually seems to have very strange effects on rendering. It seems to stop rendering at certain boundaries, and for some odd reason reselecting the Camera in the hierarchy “refreshes” this area, as can be seen here:

Update 2:

I still have no idea what is happening. If I call TileMap.CompressBounds() Unity resizes the TileMap to the Origin and Size I am manually setting it to. Using CompressBounds() instead of simply settings Size and Origin works for some reason, so I assume Unity is calling something behind the scenes to update some part of the TilemapRenderer. Ideally manually setting this should be possible somehow since CompressBounds() is most likely slower than simply calculating bounds with the knowledge of how big each chunk is.

Maybe someone has successfully manually updated Tilemap bounds before? I feel like it’s possible since why do Size and Origin have a setter then, instead of just a getter? Also I tried calling TileMap.ResizeBounds() since that sounds like what I want, but it doesn’t have the desired result. (Nothing at all seems to happen…)

Hi, I know this is an old post but it’s relevant to my current problem and it seems there’s no solution following this.

By any chance were you able to found out how to fix the lag spikes caused by TilemapRenderer.CameraBoundsCheck → WaitForJobGroupID → TilemapRenderer.CameraBoundsJob?