GUI.DrawTexture GUI.depth

Setting GUI.depth doesn't work correctly with calls to GUI.DrawTexture.

It only seems to work correctly when one of the depths is 0, then the DrawTexture call gets correctly rendered in front.

But with any other two numbers, it doesn't respect the order.

Any ideas?

GUI.depth works on a per-script basis, so you cannot use it to control depth of rendering within on OnGUI function.

Yes, of course, Im using it in different scripts.

Your response anyway implies that you think that it should work. I will try to isolate and reproduce.

Thanks

I did a check and couldn't get it to not work....

If you get a reproducible case, please submit a bug so I can take a look.

Nicholas

After a few hours of intense debugging, I found the problem.

function OnGUI()
{
 if (Event.current.type != EventType.Repaint)
   return;

  { ... many complex calculations, omitted for brevity }
  
  GUI.depth = depth;
  GUI.DrawTexture(Rect(pos.x, pos.y, size.x, size.y), texture, scaleMode);
}

can you spot the problem?

In order to avoid calculations, I was doing the Event.Repaint check thing. I though that it was correct because in this OnGUI I wasn’t creating any controls that require mouse or keyboard processing…

But the thing is that GUI.depth is also dependant of the “I’m going to call you a few times” mechanism.

Now Im going to move the complex calculations to Update(). This is also something I was trying to avoid, because I have to store the result of the calculations in intermediante member variables so that OnGUI has access to them… I was trying to avoid this variables.