0
\$\begingroup\$

I need to get the position of the bottom-left cell on my tilemap. I used Floor.CellToWorld(Floor.cellBounds.min) (Floor is the name of my tilemap) and I used Gizmos to see if it was working but it turned out to be in a weird place, the Rect Tool Also shows a wrong rect. Here's the image so I can explain better:

Rect and Cell Position

As you can see the yellow-ish part is the bottom-left part of my tilemap, the green circle (which is a wired sphere) is Floor.CellToWorld(Floor.cellBounds.min), and those two thick white lines are shown by using the Rect Tool. So judging by this info, I think it's not a programming-related issue. Does anyone know how I can fix this?

\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

enter image description here

The root cause is that removing the tiles doesn't actually make the cellBounds shrink.

For the reason of saving memory resources, the memory allocation of tilemap is progressive, only when a tile is used for the first time, cellBounds will expand to include this tile. When the tile is deleted with the eraser, cellBounds will not shrink (avoid frequent application/reclaim memory). Unity provides a button to manually reset cellBounds named Compress Tilemap Bounds.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks! That solved the problem, is there a way to do this from script though? \$\endgroup\$
    – Arian_ki
    Jun 20, 2022 at 9:13
  • 2
    \$\begingroup\$ You can use Tilemap.CompressBounds. \$\endgroup\$
    – Mangata
    Jun 20, 2022 at 9:16
  • \$\begingroup\$ Thanks again 🙏 \$\endgroup\$
    – Arian_ki
    Jun 20, 2022 at 9:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .