Setting up sorting order at runtime

Avatar
  • updated
  • Answered

Hi

I manage to set the sorting order of my shape all fine when I play with the demo parameters

Image 577

Then I would like to set that SortingOrder parameter at runtime

and Draw.sortingOrder doesn't exist.

What should I do ?

cheers

ps:

Also, am I using the documentation wrong ?

I find myself digging in the sample and library code all the time to try and

find things 

ex:

it took me a while to come up with things like

Draw.StencilComp = CompareFunction.Less;

Draw.StencilOpPass = StencilOp.Keep;

Draw.StencilRefID = 0;

Draw.StencilReadMask = 255;Draw.StencilWriteMask = 255;

Reporting a bug? please specify Unity version:
Reporting a bug? please specify Shapes version:
Reporting a bug? please specify Render Pipeline:
Built-in render pipeline
Avatar
Freya Holmér creator
  • Answered

Draw.X is for the immediate mode API, and sorting order doesn't exist in immediate mode due to the nature of how the draw calls are processed, as outlined here.

In immediate mode, the draw order is always the order in which you execute the Draw.X commands. If you want to be able to draw in any order, you'll have to use the opaque blend mode, since they make use of the depth buffer to ensure sorting is correct


Avatar
richdotgg

Thank you for the very quick answer :)

2 things are keeping me stuck

1 - on my test project, switching to opaque somehow doesn't play well with my stencil buffer Mask  (see screenshot)

2 - by making a search for BlendMode in your package code, I found 
ShapesBlendMode.Opaque
which, I guess, is the proper way to use the opaque blend mode on my shape.
But it soen't change a thing in the way it renders ¯\_(ツ)_/¯


EDIT:

I guess one of my problem is that I'm looking at sorting order between Sprites and Shapes, rather than between shapes alone


Avatar
Freya Holmér creator

yeah, Unity's sprites will render as part of the transparent queue, while immediate mode generally happens afterwards, regardless of depth (in immediate mode)

Avatar
richdotgg
Quote from Freya Holmér

yeah, Unity's sprites will render as part of the transparent queue, while immediate mode generally happens afterwards, regardless of depth (in immediate mode)

So, does that means there is zero chance of me getting Shapes to work with my app ?


Working on some sort of puzzle games where the pieces of the puzzle are sprites.
I wanted to use Shapes so that I coud animate the contour of the sprites once the puzzle is complet

animat => immediate mode
immediate mode => NO SortingOrder between shapes and sprites

end of the problem solving ?