Search Unity

Drawing UI on top of GUI.DrawTexture?

Discussion in 'UGUI & TextMesh Pro' started by GMM, Mar 13, 2015.

  1. GMM

    GMM

    Joined:
    Sep 24, 2012
    Posts:
    301
    Hi there fellow Unity users.

    I have recently begun using the new UI system and are quite liking it, but i have one major issue that i cannot seem to fix.

    I have a texture that needs to fill the screen with a dynamic width/height and that has always worked pixel perfect using the GUI.DrawTexture method in the OnGUI pass, but this does not seem to work in tandem with the new UI system.

    Rendering the texture using RawTexture on the UI makes the same effect and it will scale accordingly, but dynamically adjusting the texture gives me very slight black bars in the top and right sides of the screen. I would prefer to use the GUI.DrawTexture method and then draw the UI on top of that, but i cannot seem to get the new UI to render at a higher depth than the GUI.DrawTexture call.

    In short, how do i draw new Unity UI elements on top of a GUI.DrawTexture call?
     
    xpack3 likes this.
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Short answer is you dont. the systems were never designed to work together. the old GUI will always be on top.
     
    SimonDarksideJ likes this.
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    The good news is that getting things pixel perfect on the new UI is pretty easy.
     
  4. GMM

    GMM

    Joined:
    Sep 24, 2012
    Posts:
    301
    I have not been able to get it to be pixel perfect using the new GUI, the image always seems to have missing pixels in the sides when the image is scaled to a resolution that is not equal by multiplying by two, the image is just not streched to the boundaries of the canvas.
     
  5. Feaver1968

    Feaver1968

    Joined:
    Nov 16, 2014
    Posts:
    70
    Call me crazy, but couldn't you scale the image slightly beyond the canvas size as a hack?
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I'm not sure I understand what you're saying here. Have you tried the 'Set Native Size' button on the Image component in the UI?
     
  7. GMM

    GMM

    Joined:
    Sep 24, 2012
    Posts:
    301
    No, that wouldn't fix it as it would scale the image to its 1:1 ratio, something i wouldn't need to do unless the image has a 100% similar pixel size compared to the canvas.

    I did however fix the problem. The new UI is not happy when you serve it images that aren't an equal number on either side, so an image that is 91 pixels wide would not be able to fill the RawTexture element completely and therefore give me black borders. The fix is to check if both the width and height of the texture is an equal number, if not it should be fixed before doing the scale.
     
  8. magnus42

    magnus42

    Joined:
    Dec 7, 2017
    Posts:
    1
  9. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Well this might be the newest entry in the necroposting hall of shame.
     
    Hosnkobf likes this.