Search Unity

Issue: screenshots of GUI elements with rendertexture

Discussion in 'UGUI & TextMesh Pro' started by fertigo, Nov 7, 2014.

  1. fertigo

    fertigo

    Joined:
    Feb 15, 2014
    Posts:
    19
    I'm making a drawing / coloring app. I use uGui for stamp/sticker functionality.

    I'm trying to use a rendertexture to make a screenshot. But the GUI elements don't show up on the render texture.

    The GUI elements are on a Screen Space - Camera canvas which is rendered by my Main Camera. When I'm taking a screenshot I set the target texture of my camera to a rendertexture, take my screenshot, and reset. Everything shows up in the PNG except the GUI elements. This is my code:

    Code (CSharp):
    1.                 mainCamera.targetTexture = renderTextureFull;
    2.                 RenderTexture.active = renderTextureFull;
    3.                 mainCamera.Render ();
    4.  
    5.                 Rect portion = new Rect(0f, canvasMinY, canvasSizeX, canvasSizeY);
    6.  
    7.                 readingTextureFull.ReadPixels (portion, 0, 0);
    8.                 System.IO.File.WriteAllBytes (directoryPath + "/" + fileName + "_total.png", readingTextureFull.EncodeToPNG ());
    9.  
    10.                 mainCamera.targetTexture = null;
    11.                 RenderTexture.active = null;
    12.  
    Weird thing is that if I don't reset the main camera back to rendering to the screen (targetTexture = null) I do get the GUI elements if I save a second time. So I guess GUI elements are rendered sometime later in the render pipeline. But if I postpone everything from mainCamera.Render() onwards to the OnPostRender() event it doesn't show up so it's probably even later than that.

    A solution I thought of is using 2 cameras and don't switching the Render Target, but I can't assign a canvas to more than one camera. Does anybody know another solution for this issue or is it a Unity bug?

    I found a forum post stating that an issue was logged for a similar issue (number 631091), but can't find it back in the issue tracker.
     
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    its a Unity bug, we know about it but didnt have time to fix it for V1.
     
  3. DarkArts-Studios

    DarkArts-Studios

    Joined:
    May 2, 2013
    Posts:
    389
    +1 on this please, I have had bugs raised against my editor extension ( http://u3d.as/9tf ) , from customers.

    @phil-Unity is there a public link to that bug report for my own reference?

    Thanks
     
  4. hunterua

    hunterua

    Joined:
    Nov 5, 2009
    Posts:
    42
    Hi
    Any news on this issue ? Seems to me it still not fixed 4.6.0f3. Or may bt there is easy workaround to be able to render to texture uGUI Canvas content ?

    Thank you.
     
  5. DarkArts-Studios

    DarkArts-Studios

    Joined:
    May 2, 2013
    Posts:
    389
    @hunterua

    The only work-around I've found so far is to set the UI canvas to "World Space" rather than "Screen Space" in order to render UI elements into the render texture. Perhaps this is helpful to you? unfortunately in my case it's just not enough to solve the issue.
     
    hunterua likes this.
  6. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    it should be fixed in the next beta as well.
     
    hunterua and DarkArts-Studios like this.
  7. Malveka

    Malveka

    Joined:
    Nov 6, 2009
    Posts:
    191
    I appears this issue is still *not* fixed in 4.6.1f1. Can anyone confirm? Thanks.
     
  8. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    I can :)

    It wont even make it to the next patch release :( my fix got changed when moving to a new branch and it re broke the fix. I want to talk to the guy who changed it to figure out why before i do any other changes.
     
  9. Malveka

    Malveka

    Joined:
    Nov 6, 2009
    Posts:
    191
    Hey Phil, thanks for letting us know! FYI... I need this fix so my iVidCapPro video capture plugin can work for capturing the new UI elements
     
  10. paradizIsCool

    paradizIsCool

    Joined:
    Jul 10, 2014
    Posts:
    178
    Is this fix in 4.6.1p5 ?
     
  11. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    yea it should make it for p5 i think/hope
     
  12. cesarpo

    cesarpo

    Joined:
    Jun 8, 2013
    Posts:
    97
    I have this same problem in 4.6.2 so looks like it hasn't been fixed :(
     
  13. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    A working example of how to capture the UI to a rendertexture and how to blit that back to a scene camera's rendertarget would be nice.
     
  14. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Yea a whole bunch of internal things happened which caused a lot of UI fixes to not make it into a release quickly. I personally merge in a bunch this week for 4.6.2p1. It should include this issue
     
  15. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    Hey Phil, is there a confirmation that this made it in for 4.6.3?

    I'm not seeing any of my UI in the captures to rendertexture.. (Possible I'm still doing something wrong?)
     
  16. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    should have been in as of 4.6.2p1
     
  17. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    (I'm stuck with the webplayer, so I needed the full point release :) )
     
  18. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    then it should have been in 4.6.3 yes
     
  19. chrome-alex

    chrome-alex

    Joined:
    Dec 13, 2012
    Posts:
    19
    4.6.3f1 - the bug is still here
     
  20. artaka

    artaka

    Joined:
    Feb 19, 2013
    Posts:
    128
    I'm also experiencing this bug on 4.6.3p3
     
  21. raiden

    raiden

    Joined:
    Feb 8, 2009
    Posts:
    333
    Just purchased Screenshot Creator from DarkArts Studio, and due to this bug, I can't get screens with my UI, very frustrating :(.

    I'm on Unity 4.6.4f1
     
  22. DarkArts-Studios

    DarkArts-Studios

    Joined:
    May 2, 2013
    Posts:
    389
    @raiden I'm truly sorry about this. Many people have contacted us about this issue and we're watching this progress closely in case we need to react should Unity's fix not correct this 100% for Screenshot Creator.

    [Edit] This may or may not help you with your particular situation, but if the UI elements are set within "world space" they should render within screenshots depending on which patch level of Unity you have. It might be worth a try for you if feasible within your project.
     
  23. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    I see you updated the Asset Store description with "Please note: There is currently a known bug within Unity itself preventing non-world-space UI items from being captured. See This Forum Postfor more information. Once Unity's Developers fix this bug UI elements should be captured correctly."

    But I don't think this adequate. The fact is majority of UI is done in screen space, and your asset - unity bug or not - does not work as advertised. You need to put this notice at the top and make it explicit that you cannot currently take screenshots for Unity 4.6 and Unity 5.

    Taking App store screenshots is a pitfa and most of us bought this to relieve the pain and it's still there.
    Continuing to sell the product when it doesn't work isn't really good business - or brand - sense.

    I've had to pull my own products at times from app stores due to Unity bugs (usually informed by an irate customer). It's painful, but until it's fixed you shouldn't really be selling it - or be very plain about what works and what doesn't in very clear language.
     
    Last edited: May 5, 2015
  24. DarkArts-Studios

    DarkArts-Studios

    Joined:
    May 2, 2013
    Posts:
    389
    @sonicviz Pulling it from the store means those that *HAVE* bought it already won't have access to it. There are many happy people with the product as it stands - all those customers, who have paid and are happy, will no longer be able to download it and use it (even though they paid for it) if it's pulled. That, in our opinion, makes a lot less business sense.

    It definitely works as advertised, baring Unity UI non-worldspace UI elements (for now).
     
  25. chrome-alex

    chrome-alex

    Joined:
    Dec 13, 2012
    Posts:
    19
    shenjiexiang1994 likes this.
  26. raiden

    raiden

    Joined:
    Feb 8, 2009
    Posts:
    333
    Just updated to Unity 4.6.5f, and same thing :( no fix yet.

    @phil, how is progress coming on this issue?
     
  27. chrome-alex

    chrome-alex

    Joined:
    Dec 13, 2012
    Posts:
    19
  28. raiden

    raiden

    Joined:
    Feb 8, 2009
    Posts:
    333
    chrome.alex, how bout some usage information please?

    Thanks
     
  29. chrome-alex

    chrome-alex

    Joined:
    Dec 13, 2012
    Posts:
    19
  30. cesarpo

    cesarpo

    Joined:
    Jun 8, 2013
    Posts:
    97
    This still isn't fixed.

    Using Unity 5.0.2p2 :(
     
  31. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    Bug numbers? clearly we all need to re-send the bugs with our various repro cases.
     
  32. fermmmm

    fermmmm

    Joined:
    Oct 18, 2013
    Posts:
    129
    any news on this?
     
  33. raiden

    raiden

    Joined:
    Feb 8, 2009
    Posts:
    333
    Just tested again, and still not fixed in latest Unity 5.1.0f3 :(
     
  34. Jeff_B

    Jeff_B

    Joined:
    Mar 12, 2014
    Posts:
    5
    and still exists in 5.1.2f1
     
  35. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    Any word on this? I'm also running into it...
     
  36. plokkum

    plokkum

    Joined:
    May 28, 2013
    Posts:
    90
    Same here, any news?
     
  37. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    265
    I'm gonna be pissed if this fix makes it into 5.3 and not 4.6 :)

    *edit* think I got a limited workaround at least for my use case... as long as the Camera is enabled, and with a render texture assigned, it will render into the render texture.. so I just read that render texture and blit to the screen as needed.

    previously I was relying on camera.Render() with a disabled camera, much like you'd usually do. Still haven't tried if SetTargetBuffers() works correctly though, it wasn't before so that might be a problem for me actually.
     
    Last edited: Oct 10, 2015
  38. Sparkline

    Sparkline

    Joined:
    Feb 8, 2013
    Posts:
    121
    5.2.2 seems bug still alive(
     
  39. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    616
    5.3.6... still don't get the UI when using Texture2D.ReadPixels for screenshot. Any workarounds?
     
  40. raiden

    raiden

    Joined:
    Feb 8, 2009
    Posts:
    333
    I agree, I spent a ton of time setting my UI Canvas to world, then having to reposition and scale objects to get the UI in the screens correctly. The whole purpose for me purchasing this item was quickly get screenshots without having to do any scene/ui manipulation. It would be great if unity could fix this.
     
  41. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    What did you purchase?
     
  42. raiden

    raiden

    Joined:
    Feb 8, 2009
    Posts:
    333
    This : https://www.assetstore.unity3d.com/en/#!/content/8682

    Fantastic tool, with the exception of not being to capture the UI without the canvas being in World view. Although, my last screenshots i did, I changed everything in play mode in unity, grabbed my screens, then when I stopped play, my scene went back to normal, so that method was considerably faster than just doing screen snips.
     
  43. VicM

    VicM

    Joined:
    Mar 14, 2012
    Posts:
    22
    I still experience this bug in Unity 4.6.9f1 it is a shame to see this keeps hapenning specially when Unity guys said it is fixed. People even have reported the problem still exists in Unity 5.3.6. This is even more frustrating when you paid for a Pro version and promised bug fixes are still present with a high price tag for newer Unity versions...
     
  44. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    904
    I just submitted bug #758542 which has a super simple repro of this continuing problem in 5.3.1p1. It's completely self-contained and easy to repro in that project.

    @phil-Unity, is this a regression of something that was fixed in a past release? Is there any workaround?

    Thanks!
     
  45. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,835
    I cant believe this is still a bug after a year +. I want to take some upscaled screenshots and I have to change GUIs to do it.
     
  46. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    I have to agree, it's pretty bad.
    Any updates on this? I mean, it's been going on for a long time now. I understand that there's latency between writing code and that new code making it into a release build, but... a whole year?
     
  47. Stevanus

    Stevanus

    Joined:
    Aug 13, 2014
    Posts:
    22
    Same here still waiting.. I'm tired of taking screenshots in the slow Xcode Simulator one by one for each device.
     
  48. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,085
    i can't believe this is still a bug... it's been years!
     
  49. SAOTA

    SAOTA

    Joined:
    Feb 9, 2015
    Posts:
    220
    also interested in a workaround. just created an automated screenshot tool. unfortunately none of my UI elements carry over.
     
  50. Thavron

    Thavron

    Joined:
    Aug 29, 2012
    Posts:
    364
    Still an issue with v5.3.3 ... Anything about fixing this in 5.4?
    Or any workaround other then using "world space"?
    (I'm working on a new asset for the Asset Store so setting the canvas to world space is not an option :( )

    Edit: Vote for the bug here: https://issuetracker.unity3d.com/issues/rendertextures-do-not-include-canvas-ui-elements

    To all who need screenshots (@jeffweber, @raiden, @angrypenguin, @wheretheidivides, @Stevanus, @SAOTA):
    My asset "xARM: Aspect and Resolution Master" can create batches of screenshots at different resolutions without using RenderTexture (= not affected by this bug).
    Sorry for the marketing ... :rolleyes:
     
    Last edited: Mar 10, 2016
    angrypenguin likes this.