Search Unity

Remove physics shape on tile

Discussion in '2D' started by Deleted User, Mar 18, 2018.

Thread Status:
Not open for further replies.
  1. Deleted User

    Deleted User

    Guest

    I've tried removing the physics shape from a tile, but it just generates a new one to the shape of the sprite when I delete it.

    I was just curious if this was possible in the sprite editor because it would make tilemap colliders much easier to work with :)
     
  2. furroy

    furroy

    Joined:
    Feb 24, 2017
    Posts:
    93
    I heard there is a bug w/ Tilemap colliders you can work around by forcing it to rebuild the colliders from scratch. This is expensive, so you won't want to do this frequently.


    TilemapCollider2D fix = map.gameObject.GetComponent<TilemapCollider2D>();
    if (fix != null)
    {
    fix.enabled = false;
    fix.enabled = true;
    }
     
  3. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Try to keep proper code tags in mind, as that in-line stuff.. along with being "less nice", can also cut off text from being displayed. ;)
     
  4. Deleted User

    Deleted User

    Guest

    My problem is actually removing the physics shape from a tile.

    Imagine I have a 3x3 square of tile type A. In the center of the square is a single tile of tile type B. I want to make it so that I can apply a tile collider to the entire tileset of 9 tiles, but it recognizes that the center tile has no physics shape and thus it doesn't apply.

    I assume the tileset collider works on looking at the physics shape of a tile.

    The whole point of this is to be able to make a house and have two tiles of that house, the area for the door, have no shape applied so that the player can "enter" the house.

    It's weird, but it's be great if it worked.

    Never mind, I found this, https://docs.unity3d.com/ScriptReference/Tilemaps.Tile.ColliderType.html , and it helps immensely. Now I can designate a whole set of tiles as non collided generating. This will help a TON when creating boundaries in an RPG like world.
     
    Last edited by a moderator: Mar 20, 2018
    WallyCZ likes this.
  5. furroy

    furroy

    Joined:
    Feb 24, 2017
    Posts:
    93
    oh sorry, i just assumed you were already using that.
     
  6. greggman

    greggman

    Joined:
    Nov 30, 2013
    Posts:
    24
    Kind of confused here. I have a single image (.PNG) with all my tiles. Are you saying I need to separate tiles into 2 files (no-collision-tiles.png) and (collision-tiles.png)? Or are you saying that I need to load the tiles twice?
     
  7. blu3drag0n

    blu3drag0n

    Joined:
    Nov 9, 2018
    Posts:
    94
    Hi,

    I was dealing with this issue since 2 hours now and unfortunatly there is nothing documentated. Even there are not much finding the forum nor reddit nor stackoverflow and so on...
    BUT i figured it out whats the point!
    What you need to do is go into the folder with all the generated Tile Assets. And then select (Multiselect & change is possible) the specific tiles you DONT want to have a shape generated the collider type to "None".
    By default its "Sprite" , due to the fact that you usually import it as a Sprite.
    If you have a custom physics shape on a single tile then you have to choose "Sprite" still.
    You will find these Tile Assets in the folder that you have selected when dragging&dropping a sprite into a Tile Palette and Unity asks you to choose a folder where to store all the generated Tiles.

    Bingo!

    KR
     
    dc1998, Baconboyxy, daicoden and 3 others like this.
  8. Pixelith

    Pixelith

    Joined:
    Jun 24, 2014
    Posts:
    580
    This just seems super tedious though. If I don't specify a Custom Physics Shape, I'd hope it wouldn't add one automatically. There has to be a way for this without me having to go through 1000's of tiles.
     
  9. Gigabitten_Gaming

    Gigabitten_Gaming

    Joined:
    Jul 10, 2017
    Posts:
    32
    Unity's physics shapes for tiles is trash, to be honest. For me, it's completely unusable given the game I'm working on.I really hope they change it.
     
  10. Pixelith

    Pixelith

    Joined:
    Jun 24, 2014
    Posts:
    580
    I actually found a way around this myself that I posted awhile back. At least for the issue I mentioned. I made a script that I drag my folder into an array and check it for a defined physics shape. If it has one, leave it alone. If not, then set the tile file to no collision. It's allowed me to work with minimum layers and no editing in Photoshop needed.
     
  11. Durium

    Durium

    Joined:
    Feb 1, 2020
    Posts:
    37
    You are a lifesaver!!! thank you!
     
  12. daicoden

    daicoden

    Joined:
    Mar 21, 2022
    Posts:
    6
    You saved me!!!
     
  13. dc1998

    dc1998

    Joined:
    Feb 8, 2021
    Posts:
    2
    OH MY GOSH, YOU ARE HERO!
     
  14. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Please use the Like button to show appreciation rather than necroing threads.

    Thanks.
     
    dc1998 likes this.
Thread Status:
Not open for further replies.