Automatic Sorting on a Tilemap - Behind and In Front - Unity Tutorial

preview_player
Показать описание
In a 2D game there is no real depth. All the object are only aligned on two axes and therefore one surface. In regard of the used camera angle it might be neccessary to create some kind of fake depth so that the player gets a feeling of 3D - or also called 2.5D.
In Unity this can be done very easy based on the Y coordinate. By adjusting the "Transparency Sort Axis" Unity will handle this for you and your player will be able to be in front and also behind objects on your tilemap.

As long as you are not using complex shapes and structures this simple approach should work in most of the cases. But as it is common with tilemaps: a lot will work, but just not everything. Do no despair ;)

Useful links for other camera angles:

Relevant Videos:

=========

=========

Timestamps:
00:00​ - Intro
00:24 - The Approach
00:48​ - Preparations / Requirements
01:45 - ! URP Explanations !
02:06 - Adjusting the Sort Mode
02:​39 - Testing The Setting
02:55 - Troubleshooting
03:05 - The Pivot Point
04:55 - Rechecking the Order
05:25 - Further Information
05:45 - Thank you for watching :)
Рекомендации по теме
Комментарии
Автор

This deserves so more likes. This is through and through the automatic sorting plus covers rookie mistakes and those who might have skipped the previous tutorials. In my case, I did everything up to "troubleshooting part" and was annoyed my character was still appearing behind stuff when in front. I was using Unity default 2D capsule as prototype player character, so it obviously doesn't have the pivot at the bottom so had to make a copy and edit that sprite.

Kalahee
Автор

Amazing video! Two things I had trouble with: set the tile map renderer to individual instead of chunk, and if you have a composite collider, be sure to uncheck and recheck the "Used By Composite" button to reset after you have changed the pivot points.

kevdog
Автор

I hope you'll continue making videos soon. I followed every video in this tutorial and everything was crystal clear and very informative. I could even improvise to make it fit my game better. Thank you so much ! I'd love if you could make more videos about how to do some generative things, like for instance duplicate the background so that the character could walk as far away as he'd like and there'll always be a map to walk on, as well as make stuff pop in and out of the map (like loot boxes the player can loot for gear) and have other characters walk and interact with our player.
Anyways this was extremely helpful, I subscribed. Thank you so much.

cuddlesgamingvids
Автор

Thanks for the video! Had it working then flipped over to a sprite-lit material and magically stopped. This did the trick.

stonegolemstudios
Автор

Thanks ! Just had to set "Transparency Sort Mode" to "Custom Axis" cause it wasn't working but now it's perfect !

TurtleMan-isob
Автор

Such a straight-forward, concise, and easily understandable tutorial - glad YouTube recommend your channel! I'll start binging this series in case I miss a technique or a Unity feature. Well done!

neilmarkcorre
Автор

Really nice video! Was super surprised to see you cover URP difference and potential misconfigurations. Saved me a lot of time.

Karutapja
Автор

this was really helpful video. it's sad you haven't made any videos in a year

CryknoxDev
Автор

I had some trouble getting it to work but after a couple of minutes i realized that the mode was chunk instead of individual and then it worked

ProfKo
Автор

Excellent video, exactly what I was looking for. I am a fan of this video series

michaelbenny
Автор

Really good tutorials! Please consider continuing with them adding opponents, combat, dialogue system, inventory and so on! ;)

gibs
Автор

thank you for even considering that some might have urp.

baby-sheesh
Автор

This was what I was looking for. Thank you so much!

aurabeth
Автор

Very good!
There was, however, something else to consider that i think is very important to bring up.

What if we had 2 tiles that compose a tree, but we wanted to be able to properly sort the upper half of the tree with a player?
The appropriate sorting point we'd want on the upper half of the tree should be the same point as the lower half of the tree. but how should one accomplish this for tile assets? This has always seemed like a gray area in videos and forums.

Cameo
Автор

Thanks, this video was exactly what I was looking for!

oscart
Автор

Important: Tilemap Renderer component mode variable should be individual.

dennismmj
Автор

Why did you stop making tutorials!? 😞 Just found your channel and you do such a great job!

Chubzdoomer
Автор

your voice is so beautiful and this is a great tutorial, thx

MOREKMEKk
Автор

Unfortunately this only works when objects on your tilemap are only 1 tile high. Supposed you had a static tree or a house that was 2 tiles high in your tile palette, you draw them onto your map as 2 tiles.. It looks fine, but the sorting breaks down as it considers them like two objects, one in front of the other. Sure you can make this a sprite instead, but it means you have to do this for EVERY object higher than 1 tile.

Ziplock
Автор

"Slight" issue im having: In my game, for some reason, the game isn't sorting by individual tiles, but rather the player's y-value relative to the entire tileset's. (So, if the player is above y=0, they appear in front of everything, and if they're below y=0, they're below everything). How would I fix this?

cyanberry