Search Unity

Transparency Sort Axis inconsistency?

Discussion in '2D' started by TitoOliveira, Jul 30, 2017.

  1. TitoOliveira

    TitoOliveira

    Joined:
    Aug 4, 2014
    Posts:
    79
    I have a gif that shows the issue, but i'll explain it further.
    I have these four sprites, with their axis set at the bottom of the sprite. In the gif you can see that i test the sorting transparency against each object, and it works fine against the couch: the sprite which has the axis closer to the bottom of the screen is rendered in front.
    But this doesn't happen to the other ones and i can't figure out why, it behaves as if their axis are positioned somewhere else.

    Anyone knows what could cause this?
     
  2. CarterG81

    CarterG81

    Joined:
    Jul 25, 2013
    Posts:
    1,773
    That is because their axises are position somewhere else.

    I briefly took a look, and from the gif it looks like your pivot point (where the sprite decides to determine its sorting order from) is the default (center of the sprite).

    You need to create your own custom pivot points. Make them at the bottom, as shown in my gif's.

    Without a custom "Pivot Parent" gameobject, all sprite's pivot point will be Center (for Transparency SortingOrder) even if you set it to bottom or something else.

    To make sense of your problem,
    Go ahead & try changing the sprite's pivot to center, and I bet it will all make sense after that (why the sorting order changes, when it changes). For whatever reason, Unity didn't inform everyone that it will always be the center. They're working right now to fix it in a future update. But I wouldn't wait. Just implement the best practice in the link.

    It is best practice in Unity2D to
    have a "master parent" or 'parent-most' for all gameobjects. Make all the spriterenderers children. IMO, sprites should never be the parent-most gameobject; Always just children of another (even if empty) gameobject. It's very helpful for me that way, anyway. Being able to move around that pivot yourself via gameobject (rather than via sprite editor) is better IMO, especially for complex objects. I still set the pivot in the sprite editor to bottom or a custom one (What should be bottom) so I can zero everything out & quicken my workflow, but it still helps to create gameobjects exclusively for use as a pivot.

    In this way, your entity's transform position (master parent) will be independent from the spriterenderer gameobject. Since the master parent has a size of 1, the top/bottom/sides/center are all exactly the same. Saves you with problems like this & other pivot issues.
     
    Last edited: Aug 1, 2017
  3. Johaness_Reuben

    Johaness_Reuben

    Joined:
    Jan 27, 2016
    Posts:
    253
    Currently it uses the center of the sprite, not the pivot point. So it won't matter where your pivot points are. We are adding that functionality to use the pivot point. Coming soon. :)
     
  4. TitoOliveira

    TitoOliveira

    Joined:
    Aug 4, 2014
    Posts:
    79
    Ooh, in hindsight just jumped to the assumption it was using the pivot without actually checking. I'm glad you guys are figuring that out, it seems to be the most intuitive way.
    Thanks for the replies
     
  5. arkogelul

    arkogelul

    Joined:
    Nov 14, 2016
    Posts:
    105
    Is it now possible to use the pivot points ?
     
  6. Bishop-Games

    Bishop-Games

    Joined:
    Jun 4, 2014
    Posts:
    4
    Yes, it's a setting on the Sprite Renderer. I could be wrong, but it seems to be available since Unity 2018.3.

    upload_2018-12-8_15-21-51.png
     
    jacobhouston_unity and bassadin like this.
  7. bassadin

    bassadin

    Joined:
    Mar 17, 2019
    Posts:
    1
    Thank you so much! I spent an hour searching why that wouldn't work for me...
     
  8. Kaldrin

    Kaldrin

    Joined:
    Jul 10, 2018
    Posts:
    46
    Hello! I am having a similar issue with Unity 2019.4, but actually the sorting doesn't work at all, I've tried a ton of stuff, the custom axis Y doesn't work at all, my character is either rendered in front or behind the objects and it doesn't depend on its Y position, and I've set up the pivot points correctly.
    I am using a tilemap
     
  9. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    change tilemap renderer mode to individual instead of chunk
     
  10. carloso

    carloso

    Joined:
    Oct 6, 2016
    Posts:
    1
    Having the same issue as @Kaldrin on 2019.4 - sorting seems to work in the scene window but not in play mode. I'm on a Mac.