Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Bug TileMapCollider2D not working?

Discussion in '2D Experimental Preview' started by mgear, Sep 6, 2016.

  1. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,549
    Just briefly tried to add tilemap collider, but nothing happens, or am i missing some step?

    as in googledocs:
    - Select tilemap layer
    - Add TileMapCollider2D
    - Add a CompositeCollider2D Component. Set the Rigidbody2Ds’ Body Type to Static and set the TileMapCollider2D component to be Used By Composite

    I don't see any green collider lines, also the 2d rigidbody falls through..

    upload_2016-9-6_22-2-50.png
     
  2. Tony-Tonijn

    Tony-Tonijn

    Joined:
    Nov 13, 2013
    Posts:
    3
    I can confirm this behavior. I have tried the same thing as you, including a bunch of other things. Namely:
    • Setting the generation type to manual and trying to regenerate the composite collider that way
    • Calling the GenerateGeometry function from script via the GetComponent<CompositeCollider2D>()
    • Opening one of the example scenes from the announcement page on this forum and trying to change the tilemap there, to no effect. (Existing collision geometry does work)
    • Trying the same trick from script in the previous scenario.
    But none of these things seem to work. What does happen is that the CompositeCollider2D component does register the shapes. As the shapeCount parameter increases when you add non-attached bodies to the collider by changing the tilemap tiles. However, no collision geometry is generated. There must be a bug in the generation code that prevents the CompositeCollider2D from (re)generating new collision data. I hope this issue is fixed soon. For now, I guess we have to use the EdgeCollider2D or the PolygonCollider2D components for now.
     
  3. Tony-Tonijn

    Tony-Tonijn

    Joined:
    Nov 13, 2013
    Posts:
    3
    Ok, I did some more testing and I have found a way to get the CompositeCollider2D to work together with the TileMapCollider2D. What the CompositeCollider2D does is ONLY look at its child transforms to build the composite collision mesh. What you need to do, is make the TileMapCollider2D a child transform of the CompositeCollider2D transform. Then the tilemap will be registered and the meshes will be generated correctly. The awesome thing is that you can mix and match colliders. So if you want a TileMapCollider2D to be composed with an box or circle collider, you can do that! Which is totally rad if you ask me.

    Clarification:
    Transform with CompositeCollider2D component
    +---> Transform with TileMapCollider2D component
    +---> Other children with other 2D colliders
    +---> etc.

    This is by no means told in the documentation or communicated correctly by the Unity Team in my opinion and in this stat, thus, still a bug. But I hope I have helped you to continue to use the 2D Preview.

    As my suggestion to the Unity team, communicate why no mesh was generated. Maybe a warning message that no colliders have been found in any of it's children? Just like other warnings in the rigidbody (for example) are shown in the inspector would be much help.

    [Edit]
    So far I have only been able to produce this result inside a project where there is already a working CompositeCollider2D setup. Also, I am trying to see if the order of adding components has something to do with how this works. I have not been able to reproduce this in existing projects created with the previous preview. Tomorrow I will try creating a new project from scratch with 5.5.0a6.

    [Edit 2]
    The hypothesis that the CompositeCollider2D combination with TileMapCollider2D as stated above only works with projects created with the 5.5.0a6 2D preview build is true. I have not yet tested if the order of adding components is significant in any way.
     
    Last edited: Sep 6, 2016
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,549
    Ok, thanks - it works fine in new project.
     
  5. TheGoldenWhale

    TheGoldenWhale

    Joined:
    Jun 21, 2016
    Posts:
    1
    I am also having this issue whenever i create a TerrainTile to place in the Tilemap. The collider works fine for simple Tile assets, but not with autoTiles
     
  6. Johaness_Reuben

    Johaness_Reuben

    Unity Technologies

    Joined:
    Jan 27, 2016
    Posts:
    253
    @mgear : some incompatibility with older projects. I recreated the tile assets and it seemed to solve the problem.
    @TheGoldenWhale Will look into it
     
  7. DuongThuy

    DuongThuy

    Joined:
    Jun 28, 2016
    Posts:
    15