Search Unity

Tile Map Tilemap Draw Order

Discussion in '2D Experimental Preview' started by TSabos, Dec 6, 2016.

  1. TSabos

    TSabos

    Joined:
    Mar 8, 2015
    Posts:
    90
    Could someone explain the reasoning behind the draw order here and how it would be corrected?

    In our game we wanted to use completely free movement, so this would probably require us to draw collision tiles on everything we don't want the player to interact with instead of always walking in the middle of tiles.

    What is determining the draw order here? The pivot of all the sprites appears to have been set at .5/.25 but that would still put it at its mid bottom ish area.

    Since everything here is Default layer and Order in Layer 0, not quite understanding the logic.

    Edit: Just realized in your demo you put the character at Z=1, I would have assumed this put the character ALWAYS in front of all the "Ground" tiles at Z=1.
     

    Attached Files:

    Last edited: Dec 6, 2016
  2. AssembledVS

    AssembledVS

    Joined:
    Feb 23, 2014
    Posts:
    229
    I second this question.

    Going through the demo, unchecking all of the scripts, etc., I do not realize what determines the draw order. I even made it into a rectangular tile map and the player can still go behind/in front of a building tile.

    How is this Y-sorting determined? Is it some kind of specific tile script that I'm not noticing? Is it a setting within the inspector? I see that only some tiles are affected (like buildings and protruding trees, etc.), but it does not matter which layer they are in (buildings or ground).
     
    Last edited: Dec 6, 2016
  3. Johaness_Reuben

    Johaness_Reuben

    Unity Technologies

    Joined:
    Jan 27, 2016
    Posts:
    253
    Apologies for this. Still preparing the documentation.

    That particular example is using the Axis Distance Sort -

    • Axis Distance Sort
      • Menu: Edit > Project Settings > Graphics
        • Set the Transparency Sort Mode
          • Default - Sorts based on the Camera mode
            Perspective - Sorts based on perspective view
          • Orthographic - Sorts based on orthographic view
          • Custom Axis - Sorts based on the given axis set in Transparency Sort Axis
        • Set the Transparency Sort Axis
          • If the Transparency Sort Mode is set to Custom Axis, renderers in the scene view will be sorted based on the distance of this axis from the camera.
    In that particular scene the Main Camera has a script on it - AxisDistanceSortCameraHelper.

    Hope that helps while we get the docs ready.
     
  4. TSabos

    TSabos

    Joined:
    Mar 8, 2015
    Posts:
    90


    If you skip to 2:05, walking right behind tree trunks etc is really what we're looking to do. I was able to pull this off in a prototype by making the world non "tile" based for the interactable objects, but all the terrain was.

    What are your current goals? I can see this tile based movement but we definitely want free form movement which adds a lot of complexity to the draw order of objects. We considered trying to group tiles to share the same order in layer as the "bottom left" point, but eventually gave up due to trying to make dungeons and dungeon walls being a bit too much for our team. I'm more of a programmer, so I'm hoping the art side of our road blocks are somehow fixed with the tools you guys have in mind but I'm not quite seeing it yet.

    We had large buildings as 1 object as well and made its pivot the bottom left most part of the sprite and then sorted all objects by their pivot and world Y pos. At some point I'm sure you have to make design sacrifices like just put collision on "tiles" and keep things away from objects, but I hope whatever is coming can trump having to resort to GameMaker and other 2d iso game engines.. because well, Unity > * ;)
     
  5. Necromantic

    Necromantic

    Joined:
    Feb 11, 2013
    Posts:
    115
    My question would rather be: How do you increase the z-value of tiles on the same tilemap? I haven't found any way to draw them to a different z-coordinate. In the same way I haven't figured out how to select those tiles in the demo scene that are on z-values other than 0 like with the multi-tiled buldings.
     
  6. AssembledVS

    AssembledVS

    Joined:
    Feb 23, 2014
    Posts:
    229
    The Main Camera script was used to set the transparency sort mode and the transparency sort axis instead of within Menu: Edit > Project Settings > Graphics? I think that is all it is doing, right?

    I still don't really understand the sorting mode settings. Before this 2D Experimental build, I had a script that set all static objects' z order based on their y axis from the bottom. This is in a 2D top-down or 3/4 down game like Hyper Light Drifter and Chrono Trigger.

    How would I achieve the same effect here? This is what currently happens:

    https://imgur.com/a/NFxh2

    As you can see, going behind is fine, but my character's top is cut off when in front of the object as well.
    Using Custom Axis, sort axis 0,1,0.

    I am not sure what orthographic does, as a different combination of sort axis numbers seems to more or less not do anything.
     
  7. TSabos

    TSabos

    Joined:
    Mar 8, 2015
    Posts:
    90
    Yes, it appears to just be setting this in script opposed to project settings.

    As for your draw order issue, is the pivot point of your character set to his feet? That is still a requirement of sorting. From there, were do you expect the sort order to put the chracter behind those blocks? I also did lowest Y wins in one of my prototypes by placing a script on every single "dynamic" object. The character updated his order in layer instead of Z while all objects in editor set their order in layer with [ExecuteInEditMode] script that changed its order as you moved the tiles.

    The interpretation of this I guess is that XYZ 0 1 0 means the same thing, but only if the tile is set to Individual mode and not Chunk right?

    If you drew a building 3 tiles high then the base would need a collider and the top 2 none, but the sort order I would want entirely based off character Y pos vs base of all 3 tiles grouped together. I don't like this Z fudging option.. I hope something else can be figured out instead.

    Do they need something like "Tile Group" where you can set a tile's base as another tile? Say you painted a base tile, 4 middle tiles, and a top tile for a wizard tower.. but they could have 1-5 middle pieces. It would be great if you could tell all pieces above the base to be the same order in layer or sort "priority" however they're doing this.. based on the.. base.
     
  8. AssembledVS

    AssembledVS

    Joined:
    Feb 23, 2014
    Posts:
    229
    Yes, it's probably the pivot. It's at the center. Forgot about that! I expect that the character, barely touching the object's bottom base, to be in front. Once moving a single pixel up, the object should cover the character.

    It has to be set to individual, yes. Otherwise, I think that you'd have to use game objects for automatic sorting, which was my initial plan.

    That's right, I did the same thing. It was the z initially, but then I used order in layer instead. Dynamic objects got their own scripts and static objects' order in layer was set at the beginning of the scene.

    I never imagined it working differently. A tower's base would have a collider, but not the rest of it.

    I see what you mean. A tower that is painted with individual tiles will have each individual tile be sorted independently, meaning that the player can easily be behind and in front of several tiles at once.

    I honestly think that the simplest solution will be to break things into layers: one that covers and one that is behind. At least for my Zelda-like, I had a whole system when I was using Tiled that worked for multiple cliff levels:

    https://imgur.com/a/k00JQ

    The red collision layer was always "active," while the player kept getting switched between "violet" collision and "orange collision," depending on which cliff level she was on. Each cliff level was exported as its own mesh and I was able to assign a sorting layer to each one (I think!).

    EDIT: But I still don't understand this orthographic sorting option. It doesn't seem to do anything for me.
     
  9. TSabos

    TSabos

    Joined:
    Mar 8, 2015
    Posts:
    90
    I've done some more testing and I opted to move an entire Tree sprite over to the palette to paint and set its anchor to mid bottom. My axis sorting is 0 1 0 and sure enough.. it sorts based on Y position for us, great!

    Issues: When painting an entire sprite, unfortunately the collider is way off where it is set up in the sprite.

    Sprite
    http://imgur.com/a/yjqf2

    Painted:
    http://imgur.com/a/AqKQU

    I tested painting the entire tree (whole sprite in a palette) on a tile because it's really nice that you can simply apply the Tilemap Collider 2D to the entire tilemap opposed to having a separate collider on every single sprite by hand (old school method).

    I thought maybe this was due to it being locked to a tile, but I just dragged the tree to my hierarchy outside of any tilemap and it still offset the collider. I don't see any way to edit the physics shape of a sprite in Unity 5.4.0f3 so this may be new, buggy functionality?
     
    Last edited: Dec 7, 2016
  10. AssembledVS

    AssembledVS

    Joined:
    Feb 23, 2014
    Posts:
    229
    What sorting type are you using? Orthographic or custom axis?
    Are you able to sort non-tile game object sprites with tiles?
    I can't get it to work even with all objects' and tiles' anchors at the bottom.

    In this latest Experimental Preview, I have the "Edit Physics Shape" option within the Sprite Editor.
     
  11. TSabos

    TSabos

    Joined:
    Mar 8, 2015
    Posts:
    90
    Custom with 0 1 0.
    I was not able to correctly get sorting working outside of the tilemap. It seems if you use axis sorting, it sorts the objects outside of the tilemap at their center, but if I PAINT the tree as a whole sprite it correctly uses its pivot as the axis sort order.
    Yea sorry I meant that it's not in 5.4 so it must be bugged and broken "new" functionality in the preview ;)
     
  12. TSabos

    TSabos

    Joined:
    Mar 8, 2015
    Posts:
    90
    Is it wrong to assume we have to set the Order in Layer on each layer in the tilemap? You still need a background layer.. foliage background and then the "Dynamic" layer that has basically anything that needs to properly sort, right? Or am I still doing all of this wrong.

    I have Background 1 set to order 0, Background fluff 1, then the main content at 2, then a Foreground always in front at 3.

    Edit: Just attached a gif, right tree is built into tilemap, left is stand alone.
     

    Attached Files:

    Last edited: Dec 8, 2016
  13. AssembledVS

    AssembledVS

    Joined:
    Feb 23, 2014
    Posts:
    229
    I'd also like an answer for whether this is Unity's intended strategy.

    Doing some more testing...
    Using transparency sort mode: custom axis, transparency sort axis: 0,1,0

    Actually, the sprite game objects sort themselves beautifully, both static and dynamic. This is just with the setting above and no additional sorting scripts. The pivots are also all at the center, so it does not have to be bottom (tried bottom, top, and center, and the results are the same). It knows where the "bottom" of the sprite is for y sorting without any need to specify. But this is only for pure sprite game objects, not tiles.

    Sprites also sort with tiles, but the behavior is not the intended behavior. The GIF below shows what happens with sprites on left and tiles on right. The bright blue moving box is a sprite.

    https://imgur.com/a/1I6Y7

    I know why the behavior on right happens: each tile is its own tile/sprite (Tilemap Renderer mode: individual) and acts as such. As TSabos pointed out, this is not ideal behavior. The fix would be to simply disable sorting (by using chunk instead of individual) and place overhead tiles on a different layer from behind tiles. This is fine, but not ideal, and more so, is it intended? If so, it seems like doing any y sorting for tiles that are larger than 1 tile high would not work.

    Perhaps when selecting a bunch of tiles with the selection tool and placing that entire group, that should count as an "individual" tile? Or maybe that should be a check/uncheck option, etc.?

    The intended behavior actually happens, to some degree, with the Unity example isometric project. The "composed" tower hides the player when she is placed far enough. But the individual tiles sort by themselves as well, as long as the tower is not "composed" as a seemingly single unit. Here is a GIF of what happens:

    https://imgur.com/a/rGHPf

    Two questions:
    1. How does the above GIF's sorting work? Is it something that only works with isometric tiles and not rectangular?
    2. How are the towers "composed," anyway? I can only put the tiles together side by side(?), not one on top of the other.
     
    Last edited: Dec 8, 2016
  14. TSabos

    TSabos

    Joined:
    Mar 8, 2015
    Posts:
    90
    I think it's fair to say that most everything works as intended even on isometric diagonal tilemaps as long as everything is 1 grid high. Once you start getting monsters in game that are 2-3 tiles high, it will fall apart. This is why I placed my entire tree sprite as 1 tile.. it "sorts" itself out. Zing..

    I did this simply by moving the tree sprite over to my pallette, it then prompts to make a tile, and then you click the base of the tree and then draw it onto a tilemap layer. The only thing broken is the collision.

    This all seems wrong though, I hope they can come up with a solution where like you said.. you can select multiple tiles and it somehow uses the bottom tile's sort as a group. We kind of need a mini version of "chunk" that works on a per grouped tile basis.

    Your bottom gif seems correct... I would expect an isometric tile's sort order to be the middle of the tile vs the feet of the player. This would allow them to walk right up to the bot left and right and be in front, but as soon as you go above the center you'd be at its top left or right and behind it.
     
    AssembledVS likes this.
  15. frankriberi75

    frankriberi75

    Joined:
    Jun 9, 2018
    Posts:
    1
    hi, please someone tell me what is this demo project ?
    i want to see this isometric tile map palette editor