Search Unity

[Solved] Pure TileMap Collider doesn't work at all on build

Discussion in '2017.2 Beta' started by Edmanbosch, Oct 6, 2017.

  1. Edmanbosch

    Edmanbosch

    Joined:
    Jun 16, 2017
    Posts:
    4
    Currently testing out the TileMap system, and I noticed when using the TileMap Collider itself on a TileMap doesn't work in the build, but is fine in the editor. What's really odd is that it works fine when using a Composite collider, and also working if I set "Read/Write Enabled" to true on the TileMap sprites. If anyone knows why this is, help would be appreciated.
     
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    822
    A fix for this is coming soon, targeted for patch 1.

    In the meantime, to make this work in runtime, you can do either of the following:
    • For each Sprite used as a Tile in the Tilemap, add a Physics Shape to it by:
    1. Open the Sprite in the Sprite Editor
    2. In the Sprite Editor, select Edit Physics Shape from the dropdown
    3. Set a Physics Shape for the Sprite
    4. Apply changes
    • As you have mentioned above, set "Read/Write Enabled" to true for the Texture of the Sprite. Why this is required for now is that the shape used for the Collider is generated from the pixel outline of the Sprite. In runtime mode, there is no access to the Texture data (as "Read/Write Enabled" is false by default in runtime), which results in the TilemapCollider2D failing when alone.
     
    Edmanbosch likes this.
  3. Edmanbosch

    Edmanbosch

    Joined:
    Jun 16, 2017
    Posts:
    4
    Thanks, although you didn't seem to mention anything about the composite collider?
     
  4. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    822
    CompositeCollider2D would work too, provided that no new Tiles are added in runtime, as CompositeCollider2D stores the composited shape.
     
    Edmanbosch likes this.
  5. Edmanbosch

    Edmanbosch

    Joined:
    Jun 16, 2017
    Posts:
    4
    Oh, how interesting. Would CompositeCollider2D work when dynamically adding and removing tiles if I also set "Read/Write Enabled" to true on my sprite?
     
  6. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    822
    Yes, it would work on runtime, as the TilemapCollider2D would be able to generate an outline for the Sprite and update itself, and the CompositeCollider2D would pick up the changes in the TilemapCollider2D. Having a Physics Shape for the Sprite would work too.
     
    Edmanbosch likes this.
unityunity