Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Tilemap - Bounds (bug?)

Discussion in '2017.2 Beta' started by luispedrofonseca, Oct 11, 2017.

  1. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    901
    Hi, I'm trying to know the current size of a tile map and for that I've experimented with "localBounds" and "cellBounds" but their behaviour is a bit weird.

    Here's a video of what's happening: https://www.dropbox.com/s/gyquw76k4j6hwqy/tilemap_bug.mp4?dl=0

    The white border is a gizmo drawing the bounds rectangle ("cellBounds" in this case).

    Basically it seems that once the bounds grow they never shrink back even if no tile is present.

    Any hints?

    [EDIT]
    I just noticed there's a "CompressBounds" method that does what I need - removes the empty bounds space. It's just a bit weird this has to be done manually, but I guess that will have to do.
    In the meantime, if someone knows a better way to do this please let me know!
     
    Last edited: Oct 11, 2017
    Frizle, jehk27 and info_unity581 like this.
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    992
    The bounds of the Tilemap represents the largest previously painted area. CompressBounds will compress the bounds to the extents of actual filled Tiles, and is a rather expensive operation so it is not called automatically. CompressBounds can be called from the menu dropdown of the Tilemap inspector (using the gear dropdown button).