Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Released] Easy Isometric Sorting

Discussion in 'Assets and Asset Store' started by CreativeSpore, Apr 28, 2015.

  1. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Easy Isometric Sorting
    http://u3d.as/fFf

    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.
    • Features:
      • Full Source Code (NEW v1.0.1)
      • Full Documentation
      • 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
    NoIsoSprite.gif

    Sprite with multiple parts with Easy Isometric Sorting
    IsoSprite.gif

    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.
     
    Last edited: Aug 6, 2015
    Gozdek likes this.
  2. b4c5p4c3

    b4c5p4c3

    Joined:
    Jan 4, 2013
    Posts:
    537
    Looks useful
     
  3. Member123456

    Member123456

    Joined:
    Oct 17, 2012
    Posts:
    237
    I like the look of this.
     
  4. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Easy Isometric Sorting is now available!
     
  5. Member123456

    Member123456

    Joined:
    Oct 17, 2012
    Posts:
    237
    Used it, and it is simply brilliant!
     
    CreativeSpore likes this.
  6. b4c5p4c3

    b4c5p4c3

    Joined:
    Jan 4, 2013
    Posts:
    537
    Where's the link to the asset store?
     
  7. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Here http://u3d.as/fFf
     
  8. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    50% off for a limited time!
     
  9. MIK3K

    MIK3K

    Joined:
    Sep 10, 2014
    Posts:
    144
    I don't even need this but bought it if I ever make a 2D game. Same with your great RPG map maker. You make some awesome tools!
     
    CreativeSpore likes this.
  10. bigdaddio

    bigdaddio

    Joined:
    May 18, 2009
    Posts:
    220
    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.
     
  11. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Yes, you can. Change the sorting order of any part and call Invalidate to save changes.
     
  12. bigdaddio

    bigdaddio

    Joined:
    May 18, 2009
    Posts:
    220
    That really didn't make sense to me.
     
  13. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    You can change the sorting order of the parts accordingly and call the Invalidate method of the script component IsoSpriteSorting.
    Like GetComponent<IsoSpriteSorting>().Invalidate()
     
  14. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    New version released 1.0.1 with full source code!
     
  15. Chaosgod_Esper

    Chaosgod_Esper

    Joined:
    Oct 25, 2012
    Posts:
    295
    Is there a way to deactivate the script at runtime?
    GetComponent can´t find the Component ._.
     
  16. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    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.
     
  17. Chaosgod_Esper

    Chaosgod_Esper

    Joined:
    Oct 25, 2012
    Posts:
    295
    the object is a GO of an array, inside a foreach loop:
    Code (csharp):
    1.  
    2. // tile = the current array index. The Array is a 2D List of a tilemap class,
    3. //          holding a tileID, object, tileType, terrainType and
    4. //          other options each index.
    5.  
    6. tile.object.GetComponent<IsoSpriteSorting>().setActive(false);
    7.  
    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.
     
    Last edited: Oct 1, 2015
  18. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Are you sure the tile.object is not null? What is the exception message you have? Is it happening if you change the line for this code?:
    Code (CSharp):
    1.  
    2. if( tile != null && tile.object != null)
    3. {
    4.   tile.object.GetComponentsInChildren<IsoSpriteSorting>(true)[0].setActive(false);
    5. }
    6.  
     
  19. Chibig1

    Chibig1

    Joined:
    Oct 19, 2015
    Posts:
    5
    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<IsoSpriteSorting>().Invalidate() but it hasn't any effect.
    Can you help me?
    If you can explain me how works the parents-childs relation order...

    Your plugin works great!
     
  20. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Hi,

    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.
     
  21. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Hi, will this asset work in this situation?

    Everything in the game is in 3D with a perspective camera, except for the NPCs. Each NPC is made up of 10 to 20 2D sprites with skeletal animation (Puppet2D). The camera is fixed and looking straight ahead on the Z axis..

    The view is 1st person so that you, the unseen player, are looking out over a counter at customers (the NPCs) in front of the counter. The customers come in the shop and walk up to the counter or walk away from the counter and leave the shop (on the Z axis). Since the view is perspective, the customers are smaller the further away they are from the counter/camera. Some customers are in front of other customers, and like I said, each customer is made up of many sprites so there needs to be local depth sorting for the sprites in each customer, and there needs to be global depth sorting for the position of each customer in the 3D world relative to the counter and the other customers.

    Also I am using the latest version of Unity 5.3.

    Thanks.
     
  22. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Hi there,

    Yes, you can sort the gameobject using any axis, in your case, Z.
    I have made a test with Unity 5.3.1f1 with a 2D character at z = 0, a 3D cube at z = 30 and another character at z = 50.
    upload_2016-1-19_11-32-27.png
     
  23. NechyporukEvgen

    NechyporukEvgen

    Joined:
    Sep 3, 2013
    Posts:
    35
    Hi, how to be in this situation? Diagonal isometric sprite with a single point, not correctly display the sprites. Recommend something?
     

    Attached Files:

  24. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    You have to split the house in blocks.
    To make isometric sorting work, all elements should be a square. 1x1. 2x2 ( with diamond shape because of the isometric view ).
    This post in a forum explain better how to solve your problem with the house.
    https://forums.tigsource.com/index.php?topic=7333.0
     
  25. NechyporukEvgen

    NechyporukEvgen

    Joined:
    Sep 3, 2013
    Posts:
    35
    Thank you, I try to follow your advice
     
  26. AlanGreyjoy

    AlanGreyjoy

    Joined:
    Jul 25, 2014
    Posts:
    192
    Love the asset, may buy it.

    Can I use this for a 3d character?

    I have to use a 3D model for my top down game (it makes sense for what I am doing)

    Is there a way you can make this work for the 3D character?

    Thanks man!

    Still deciding between rpg map maker or the super tile one lol.

    I wonder if I could use this with this asset
    https://www.assetstore.unity3d.com/en/#!/content/73945

    That would be a blessing...
     
    Last edited: Feb 24, 2017
  27. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Hi there,

    This tool is working changing the sorting order of the renderers found in the gameObject.
    So this will work with 3D models if they are rendered using a shader compatible with a sorting order.
    So far the only shader I know that works with this is the Sprites/Default and the Sprites/Diffuse.
     
  28. AlanGreyjoy

    AlanGreyjoy

    Joined:
    Jul 25, 2014
    Posts:
    192
    That would work fine for objects that don't overlap each other. But with something like a character model, the objects just bleed into each other with they use the Sprites/Default.

    I posted in the jobs offered area for a shader. We'll see what happens.
     
  29. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Great! Let me know if that is easy to achieve. I am also interested.
     
  30. cheesecow

    cheesecow

    Joined:
    Jan 21, 2017
    Posts:
    2
    Hello!
    I just bought this tool as it seemed like what I needed to solve my sorting issues as it says it will sort things by the renderers attached to objects. I'm using Skinned Mesh Renderer's through an Anima2D tutorial I followed to animate my characters and this doesn't seem to pick up on those renderers. Perhaps I'm not using the skinned meshes properly and this isn't a good use case for this tool? Wondering if anyone has run into this scenario before? I've included a screenshot of how my character is laid out for reference.
     

    Attached Files:

  31. cheesecow

    cheesecow

    Joined:
    Jan 21, 2017
    Posts:
    2
    Ok I've found a tutorial for 5.6+ which uses sorting groups to keep the sprites from getting jumbled together. I'm taking a look at the script for EIS to see if I can hack in using the sorting group to order the sprites instead. Otherwise I guess I can use the "order in layer" on the sorting groups based off of a y-axis position to sort what I have. Would love to get this working through EIS though as it seems like what I need, if @CreativeSpore you have a suggestion where to look in your script I'd be happy to try to code it up and make this work :)
     
  32. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Hi there!
    I found the problem with Anima2D. The OnWillRenderObject is setting the sorting order back to it's previous value.
    Commenting this line will fix the problem:
    upload_2017-9-8_21-20-15.png

    I will find a better way to fix it without modifying the Anima2D script and let you know if it was possible or not.
     
  33. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    I have updated the asset to update the sorting order during the camera OnPreRender instead of during the Update, fixing the issues using Anima2D or any other asset that changes the sorting order.
    If you want the patch, send me an email and I will reply back the patch.
     
  34. FDPC

    FDPC

    Joined:
    Oct 23, 2017
    Posts:
    2
    Hi,

    Before buy your asset i would like to know if it work with :
    - prerendered background
    - 3D player / enemy
    - prerendered vegetation animated

    Look like Pillars of Eternity Game.
    Thx.
     
  35. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Hi there!
    This asset is basically useful to sort characters made of pieces, like the ones you see with Anima2D, for example.
    Normally, this characters sort the difference pieces using a different sorting order but the same sorting layer.
    This tool will change the sorting order according to the sorting axis position to make it be rendered properly over or under another character.
    If you use 3D models for characters, it will be useless. If you use a single sprite you can sort it by changing the sorting order easily. But if you have characters with a lot of pieces, it is useful to sort all the pieces automatically.

    If you have more questions or the answer wasn't clear enough don't hesitate to ask again.
     
  36. FDPC

    FDPC

    Joined:
    Oct 23, 2017
    Posts:
    2
    Hi,

    Thanks for your reply.
    But my english is maybe to bad to understand all...

    If i résume : it work with 2D but not with 3D.
    Isn’t it ?

    So how can ordering 2D and 3D ?
     
  37. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    This is just a way to do this but you can render to texture the 3D model of the character and render the texture like a 2D character.