Search Unity

Feedback 2D Tilemap Individual Sorting - Set Cell Sorting Point

Discussion in '2D' started by DanielThomas, Oct 4, 2020.

  1. DanielThomas

    DanielThomas

    Joined:
    Mar 30, 2013
    Posts:
    111
    Hi,
    So I'm trying to make use of the individual sorting mode, but it seems it's only possible to sort from the middle of the tiles/cells?

    Would it be possible to add an option to sort from different corners of the cell? I'm particularly interested in sorting from the bottom.

    Usecase, let's use a piece of a pole as an example (see attached image for illustrations):
    Objects that are 2 tiles where you want the bottom tile to act as the collider and the top be something the player can walk behind.

    Illustration 2: As long as the player is above the middle of the cell everything is sorting correctly.

    Illustration 3:
    But as soon as the player is below the pole will sort below. The player can walk below the middle since the collider is not one full cell.

    Illustration 1: And you can't just put the top fence tile to a higher sorting layer as the player is taller than one cell, meaning he will be able to cover more than 1 cell.


    This is of course already possible but it ends up being a mess where you set the pivot in each tile sprite and change the anchoring.
     

    Attached Files:

    Last edited: Oct 4, 2020
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    So the problem is that you want to automatically have correct pivot points without going into the SpriteEditor and setting them? This could be possible with an Editor script that helps you process a texture and adjust its pivots.

    Take a look at the TextureImporter scripting API
    https://docs.unity3d.com/ScriptReference/TextureImporter.html
    https://docs.unity3d.com/ScriptReference/TextureImporter-spritesheet.html

    In particular, the spritesheet field. It uses SpriteMetaData
    https://docs.unity3d.com/ScriptReference/SpriteMetaData.html

    A outline for the script could be as follows:
    And you're done. Just run the editor script whenever you want to mass-process a new texture.
     
    eses likes this.
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    "This could be possible with an Editor script that helps you process a texture and adjust its pivots."

    This should work. IIRC I did this a while back using SpriteMetaData.
     
    Lo-renzo likes this.
  4. DanielThomas

    DanielThomas

    Joined:
    Mar 30, 2013
    Posts:
    111
    Thank you for the replies! I get how this would solve it.

    This was in hope as feedback to the Unity team, I was hoping for an option on the tilemap component to have a "Cell Tile Sort Point" with the option to select bottom.This way you would only need a tilemap/layer for everything you want to have sorted this way. Might be it's not that trivial to implement - but for me, it would simplify the workflow.
     
  5. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    We could add this to the Tilemap component, but this would create a discrepancy between Tiles and Sprites with different pivots, eg. SpriteRenderers sorting based on the pivot of a Sprite set to the bottom right, while TilemapRenderers sorting based on the bottom left for the same Sprite. Could you share with us your use case on this? Thanks!
     
  6. DanielThomas

    DanielThomas

    Joined:
    Mar 30, 2013
    Posts:
    111
    My use case would be in the first post, if it's not clear just let me know and I'll try and clarify.
    But after some experimenting, I think it's fine already. What one can do is reslice the sprites and set pivot to bottom, and select to keep the already created slices (so tiles don't loose reference). And change the anchor point to the bottom of the individual sorting tilemap component. So should be all good.