- Home /
Weird sortingOrder behavior
hi guys, This is driving me crazy. Hopefully someone can help! I'm trying to order my sprites, but weird things are happening.
I essentially have this script attached to a gameObject:
private Renderer r;
public void Start() {
r = gameObject.GetComponent<Renderer>();
if (!r) {
print("???");
}
r.sortingOrder = 4000;
}
private void Update() {
r.sortingOrder = 50000;
}
When I run this, and check the game object in editor, the Order in Layer = -15536 (why?!)
If I comment out the 'r.sortingOrder = 50000;' line from the Update method, and run the game, it works as expected...Order in Layer= 4000
what's going on here? I have other objects with sprites that can change sortingOrder in Update() correctly.... what things could be effecting this?
thanks!
p.s. using SpriteRenderer type has same results.
Answer by naviln · Oct 29, 2019 at 11:36 AM
Hi buddy, Check the manual for renderer.sortingOrder: https://docs.unity3d.com/ScriptReference/Renderer-sortingOrder.html
Looks like its a signed integer: this means that its value must be between -32768 and 32767.
50000 is too high!
Thanks! Haven't confirmed yet, but that must be it... so simple
Your answer
Follow this Question
Related Questions
Rendering Command Buffer issue while trying to apply postprocessing effects 0 Answers
Why isn't object rendering the right material? 1 Answer
Unity 5.2 Text Rendering issue 0 Answers
Can unity render 2lak polygon mesh in Gear VR 0 Answers
[Performance] RenderForwardAlpha performance issue on Android with Unity 5.3.0f4 0 Answers