Search Unity

Composite Collider 2D not updating after changing sprite's physics shape

Discussion in '2D' started by blastedw, May 9, 2019.

  1. blastedw

    blastedw

    Joined:
    Apr 29, 2019
    Posts:
    13
    I'm using tilemaps and have set up everything and started doing some level design. I noticed that the composite physics shape generated is not perfect (especially for slopes). So I went in to the sprite's Sprite Editor, and fine-tuned the physics shape.

    I then click on apply. However, the composite collider doesn't get updated (generation type is synchronous). When I go back to the sprite editor, the updated physics shape is sill there.

    Am I missing a step? Why isn't the collider updating?

    EDIT
    A workaround which I found out is to select the changed tile, set the Collider Type to Grid and then back to Sprite. Doesn't make sense but works.
     
    Last edited: May 9, 2019
    jphoffmann likes this.
  2. The_wARmAcH1n3

    The_wARmAcH1n3

    Joined:
    Aug 5, 2023
    Posts:
    92
    I deactivate first the composite collider, then the tilemap collider. After that I save the scene and load another scene. Then I load the scene again, and active the tilemap collider and then the composite collider, then it will be updated.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,475
    The CompositeCollider2D will always update when one of the Colliders using it change. If you change a BoxCollider2D using it, the composite updates. If you change a PolygonCollider2D using it, the same happens. What you're saying is that you're changing the shape outline of the Sprite originally used as a template for when the collider was created and you expect all the colliders that that originally used that sprite (and its physics outlline) to somehow know about this irrelevant of whether you've edited those colliders manually or not. This isn't how it works. The whole scene won't get update. You need to author your stuff correctly before you start splashing its stuff around the scene.

    When you add a PolygonCollider2D, it looks for any SpriteRenderer2D on it and uses the Sprite physics outline as its start. It won't ever look at it again as it's physics, not a renderer monitor; that would be super expensive. The same goes for the TilemapCollider2D which only updates when the Tilemap has a tile set or when it's first enabled.

    So, the TilemapCollider2D will take a copy of the outline and create the appropriate physics shapes when you assign a tile. If you're using a composite on this then it'll update. If you change the sprite, the tilemap system doesn't update the TilemapCollider2D for all the tiles and this has nothing to do with the composite or the physics system, it's how the Tilemap works.

    Cycling the TilemapCollider2D off/on means it has to redo all of them so this is why it "updates".

    So in the end, this was a choice for the Tilemap (not the TilemapCollider2D as the Tilemap talks to it) in that it doesn't periodically check when the sprite physics shape updates.

    It's not a bug so it being "5 years" isn't relevant. On this note, please do not necropost on the forums. Simply create your own thread with your own problems.

    Thanks.