Get 2D Tilemap size

Hey all, I’m trying to get the tilemap size either by tile count or actual width. The tilemap is currently a 2x2 map with each tile being 16x16. I’ve tried:

m.GetComponent().size which returns (35,21).

m.GetComponent().cellBounds.size which also returns (35,21).

I’m expecting to get back (32, 32) or (2,2), but I’m obviously doing this incorrectly. How do I go about getting either the tilecount, or the actual bounds of the tilemap?

1 Like

I found the solution. You have to call the CompressBounds method from the Tilemap and then you get the actual size in tiles:

m.GetComponent().CompressBounds();

m.GetComponent().size now returns (2,2) !

9 Likes

Great that you could figure it out by yourself, and thank you for coming back and posting the solution to your question!

1 Like