This script uses the camera to set the sortingOrder. It works perfectly but with this method I need to set it in update, and with 1000-ish object with this script (of which 980 are static) this feels really wasteful (?). But not sure how I can create a Script that only sets the position on Start() if the object is static, something like:
You can use the Transparency Sort Mode and Transparency Sort Axis found Edit > Project Settings > Graphics, or Camera.transparencySortMode, to set the automatic sorting method.
It sounds like you’d probably want something like this:
Camera cam = Camera.main;
cam.transparencySortMode = TransparencySortMode.CustomAxis;
cam.transparencySortAxis = cam.transform.up;
Does this not require sorting layers?
Where would I add that code?
Would I still use orthographic camera?
Should I make any changes in “Edit > Project Settings > Graphics”?
Should I keep my old Sorting Script or replace it, as mentioned I want the drawing order to only be set once on static objects.
This isn’t a new addition to your system, it’s changing what Unity is already doing. So that makes it clear that SortingOrder and associated properties will take priority over this setting.
If two objects have the same sorting properties, they will be sorted using this sort mode, which is why they sort by depth by default. Now, instead, they will sort based on the camera’s up vector.
If your camera never changes orientation, you can set that once from any script in Awake. If it does rotate at all, you’ll have to update that setting with the new up vector.
Hi thanks for helping. I tried adding your code to the Awake() on my Camera. That is the only change I made (maybe I’m still misunderstanding you), and I get the same effect as I did before (i.e it sets sorting layer on Start(), but since I move and Im still using:
If your camera never rotates, then you don’t need that line anymore. Your sprites will automatically sort based on their position on the camera’s local Y axis.
Do you know why this stops working when I add another sorting layer? :S
Not even doing anything w it, just added one and poof; stopped sorting. Works again when I remove the Sorting Layer I created