Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GUI.DrawTexture GUI.depth

Discussion in 'Immediate Mode GUI (IMGUI)' started by JohnGalt, Apr 12, 2008.

  1. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    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?
     
  2. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    GUI.depth works on a per-script basis, so you cannot use it to control depth of rendering within on OnGUI function.
     
  3. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    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
     
  4. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    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
     
  5. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    After a few hours of intense debugging, I found the problem.

    Code (csharp):
    1.  
    2. function OnGUI()
    3. {
    4.  if (Event.current.type != EventType.Repaint)
    5.    return;
    6.  
    7.   { ... many complex calculations, omitted for brevity }
    8.  
    9.   GUI.depth = depth;
    10.   GUI.DrawTexture(Rect(pos.x, pos.y, size.x, size.y), texture, scaleMode);
    11. }
    12.  
    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.