The Easy Isometric Sorting provides you a very simplified way to sort your sprite objects by a chosen axis.
You don’t need to change the Z position according to the Y position, neither change the sorting order of each part of the sprite nor change the layer.
All you need is attach the IsoSpriteSorting script to any object, and all its renderer children will be sorted according to the position of parent object in the sorting axis.
You can have objects made with different render parts with an specific sorting order, like a Puppet2D character, and it will be sorted as well.
Automatic sorting by gameobject and sorting axis position
Work both in play and edit mode
Choose the sorting axis
Change sorting base position easily by dragging dot gizmo
All with a single script
Sprite with multiple parts without Easy Isometric Sorting
Sprite with multiple parts with Easy Isometric Sorting
How it works
In Unity, render objects are sorted first by layer then by sorting order, then by distance to camera.
In an isometric game or in a beat em up this is a problem as you want to sort the characters by axis position.
If you have characters using a single sprite it could be achieved by changing sorting order, but it’s more complicated when using characters made by multiple parts for legs, arms, head, weapon, etc.
Sorting order has also a limit of 16 bits, so if you set the sorting order by z position, for example, you can only place your characters between -32768 and 32767. But also, if you use multiple parts, you need to sort all parts of a characters so they keep the order locally to the characters and by axis position as well.
All this script does is display a square with the center to be used as sorting offset and manage to sort all objects being rendered using all possible sorting order values automatically.
So it will be able to sort up to 65536 render parts being rendered by any camera, so it will sort only visible parts. Enough for a game with good performance.
The script has been also optimized to make this sorting really fast with almost no performance lost in the process and it’s managed itself so you don’t need another manager script in the scene.
If you have any questions or improvements you would like to see, let me know.
I hope this script is useful for your games or any of your work.
I have purchased this and have an issue, or should I say question. Can I change the sorting on the fly? I have a char that holds a weapon, now when walking east the weapon is in front of the body, when walking west I want it behind, of course the arms shield etc too.
You can change the sorting order of the parts accordingly and call the Invalidate method of the script component IsoSpriteSorting.
Like GetComponent().Invalidate()
Are you sure you are calling GetComponent in the object containing the component? If you are calling this in the parent object, you should use GetComponentInChildren or GetComponentsInChildren and pass true as second parameter to find inactive components.
You should keep a reference to the component in the Start method before deactivating it, so you don’t need to call GetComponentsInChildren.
the object is a GO of an array, inside a foreach loop:
// tile = the current array index. The Array is a 2D List of a tilemap class,
// holding a tileID, object, tileType, terrainType and
// other options each index.
tile.object.GetComponent<IsoSpriteSorting>().setActive(false);
The Component is attached and activ, but GetComponent isn’t finding it.
I need the component to be called once, and then deactivate it, so i can change the objects Z without resorting.
Hello!
I have some problems when I change the parent of an object. For example, I have an object and a puppet character (both with iso order script), when the character take the object (it’s previously in the scenario), I set the character’s hand as parent of the object. But, the sorting order not change relative to the new parent.
I try to setting the sorting order by code and then call to object.GetComponent().Invalidate() but it hasn’t any effect.
Can you help me?
If you can explain me how works the parents-childs relation order…
I didn’t understand exactly what was your problem, but I am going to explain how this asset works so maybe you know what is happening.
When you attach the IsoSpriteSorting script to an object, it is registering all renders found in the object and children objects using the sortingOrder to sort them. This way, the script is changing this sorting order later according to the position on the screen.
For example, if you have a character with a body a shield and a sword and they have a sorting order of 10, 15 and 18, the script will change the order later to, for example, 0, 1 and 2. It will keep the order position but not the numbers. And they will be consecutive.
For example, the top character will have values of 0,1,2 and the one behind it 3,4,5.
So, if you change the character adding or removing parts, you need to call the Invalidate to register all renders again. But if you add a part in the middle, lets say a helmet, that should be over the body, you have to give a new order to all parts again.
Body (0)
Helmet(1)
Shield(2)
Sword(3)
Then call Invalidate.
Only the parent should have the IsoSpriteSorting script, don’t add it to the children objects or they will register twice the renders.