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. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

[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:
    1,055
    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.
     
    sidato83 and Edmanbosch like 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:
    1,055
    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:
    1,055
    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.