How to rearrange sorting layers via script?

Hi,

I know you can access and change the order of sprites within a sorting layer via gameObject.renderer.sortingOrder.

But is there a scripting way to change the order of the sorting layers themselves?

In the Unity editor you can manually change the order of the sorting layers by means of dragging & dropping in the EditProject SettingsTags and LayersPanel.

But is there a way to do it with script?

Best regards

Use Renderer.sortingOrder. So for example if you were changing the sorting order of the player it would be: player.GetComponent().sortingOrder = 1 (for example);

Hope this helps! :smiley:

10 years later i have the same issue lol…