Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Feedback Feature Request: Tilemap: per-tile collision and features

Discussion in '2D' started by Marscaleb, Nov 10, 2019.

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    389
    There is a basic feature that I am honestly surprised is not in Unity already.

    In the Tilemaps, Unity already saves a "tile" asset that is separate from both the original art asset and the tile palette asset. If I could edit, adjust, or outright add properties to this asset, it would GREATLY improve the usability of the tilemaps.
    In particular, I would like to be able to customize the collision of each individual tile with something akin to the same level I can adjust them for an object in my scene (like a prefab.) Most commonly, I just need to be able to have a tile either have no collision or a standard box collision. But there are some tiles that I would want to have special collisions. Slopes are an easy example. Also, some tiles I just want to be half-height, or maybe just have the collider a few pixels shorter on one side. Maybe it's a tile I want to have a one-way collider.
    Ideally, I would want to be able to craft an edge collider or a polygon collider, where I can manually adjust each point to create the shape I want.
    Then I save this to the tile asset, and then any time I use this tile in my tilemap it will automatically have this collision, just as if that tile asset were a prefab.

    On top of that, imagine if I could adjust other properties. What if I could add scripts to specific tiles so that they are automatically utilizing special functions wherever they are in a map. I could attach a script to a ladder tile so that the player can climb it, just because I painted it into the scene.

    If attaching a script to a tile would be too much work to implement, I could still get a lot of the same functionality if unity just allowed me to set custom variables to specific tile assets. If I had a few pre-defined fields that I could assign values to, even if not an ability to create whole new variables, it would do a lot. With a simple function that will let a game object check for tiles on a tile map that it is touching/near/etc, I could read those custom values from a player script and then act accordingly.

    Likewise if adding a real 2D collider to a tile asset is not feasible, just add an option to select a user-defined collision. Elsewhere in the editor I could create a list of colliders where I can tweak them as I need to create my slopes and other shapes. Then within the tile asset I can select which custom collider to use.

    Also, personally I think it would be more user-friendly if I could set these properties within the tile palette window, or at least be able to select a tile from the tile palette window and have its tile asset be shown in the inspector. I imagine I would prefer to navigate the tiles from within the tile palette window rather than within the project window.

    I do not believe that this feature I have suggested needs to conflict with the current method of being able to add a Tilemap Collider to a layer. That feature is already pretty useful and covers 95% of how most of us use tilemaps. I think the ideal solution is that a Tilemap Collider would only apply a collider to tiles whose asset does not have a special collision set. But some people may want the Tilemap Collider to override a tile-specific collision, so perhaps there could be an option added to the Tilemap Collider to set who overrides who.

    These are the features I would like to see with the tilemap. Let me know what you think. Or if there is a better place to mention this in the hopes that it gets added to the editor.
     
  2. jeffreyschoch

    jeffreyschoch

    Joined:
    Jan 21, 2015
    Posts:
    2,635
    You can edit the physics shape for a sprite in the sprite editor, using the dropdown at the top left to switch to physics shape.

    Then on your tile you can select whether the sprite will use a grid-shaped physics collider, or a sprite-specific one.
    Untitled.png

    You can also have each tile spawn a specific prefab either by coding your own Tile class and setting the "gameObject" field of the Tile, or by setting the inspector to debug mode using the top right three-lines menu, and setting it on the Tile asset there:
    Capture.PNG

    I believe all the things you've mentioned are doable in the current system.

    Check out the 2D extras repo here for more examples of scripted tiles and brushes:
    https://github.com/Unity-Technologies/2d-extras