Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Sort order of individual tiles

Discussion in '2D Experimental Preview' started by stretchhog, Dec 22, 2016.

  1. stretchhog

    stretchhog

    Joined:
    Oct 26, 2016
    Posts:
    2
    The arrival of the Tilemap is beyond awesome. I've been playing around with it and diving into the API. However, to draw the player in-front-of or behind GameObjects was simple before with a simple sorting script; checking the location of the player, the location of the sprite and setting the sort order on the SpriteRender depending on y-values.

    However, it seems that is not possible for individual tiles in a Tilemap, only for the entire layer.
    How would I go about and sort the drawing order of tiles depending on the players location? Any tips? Can it be done with the Tilemap or is there perhaps a better way to sort?
     
  2. weeeBox

    weeeBox

    Joined:
    Jun 2, 2014
    Posts:
    271
    I'm trying to figure out the very same thing: ended up having a few tile maps with different sorting layers
     
  3. AssembledVS

    AssembledVS

    Joined:
    Feb 23, 2014
    Posts:
    248
    If a tilemap is set to "individual" instead of "chunk," each tile is sorted individually for me.

    However, in a top-down game, the issue is that a tower, for example, is composed of several tiles, and if you're behind it, they all sort individually, not as one cohesive tower. You will thus be behind some of the tower's tiles while also in front of some other tiles.

    I think that the only solution now is to use two different layers of tiles that cover (like the tower's top) and tiles that the player/NPC covers (like the tower's base).

    Unity should implement a better solution however. My suggestion is to have tiles behave cohesively if selecting a group of them (and possibly checking a bool box like 'sort whole selection' within the tilemap). This way, the bottom tile's bottom acts as the minimum y threshold.
     
  4. stretchhog

    stretchhog

    Joined:
    Oct 26, 2016
    Posts:
    2
    That's what I ended up doing as well, but it seems like a bad smell in design :).
     
    weeeBox likes this.
  5. Samacvuk

    Samacvuk

    Joined:
    Jan 8, 2017
    Posts:
    30
    anyone figured out a better workflow ?