Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Capture screenshots which include the UI?

Discussion in 'UGUI & TextMesh Pro' started by davebuchhofer, Oct 14, 2014.

  1. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    Hey guys, how would one go about capturing a screenshot of the game with the new GUI rig? in the Webplayer.

    Previously, I would

    Code (csharp):
    1.  
    2.         Texture2D screenShot = new Texture2D(1920, 1080, TextureFormat.RGB24, false);
    3.         RenderTexture rt = new RenderTexture(screenShot.width, screenShot.height, 24);
    4.  
    5.         //Render from all!
    6.         foreach (Camera cam in Camera.allCameras)
    7.         {
    8.             RenderTexture prev = cam.targetTexture;
    9.             cam.targetTexture = rt;
    10.             cam.Render();
    11.             cam.targetTexture = prev;
    12.         }
    13.  
    14.         RenderTexture.active = rt;
    15.         screenShot.ReadPixels(new Rect(0, 0, screenShot.width, screenShot.height), 0, 0);
    16.  
    17. //various other post processing here..
    18.  
    19.         screenShot.Apply();
    20.  
    21.         SaveScreenshotToGallery(screenShot);
    22.  
    Is there an extra UI camera that I can render in also?
     
  2. jim0_o

    jim0_o

    Joined:
    Jul 14, 2013
    Posts:
    6
    What is your Canvas Render Mode set to?
     
  3. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    Screen space overlay for the main ui
     
  4. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    Switched to a Screen Space - Camera to try and work around the issue, to no avail, my new uiCamera does show up in the allcameras listing, but rendering it into a texture does not appear to give any results.

    Exposed a couple problems that should be bug reports.

    ScreenSpace - Camera + Reference resolution = some shall we say, non intuitive values output in the scales and Z depths of things.
    Instantiating ui prefabs onto a screen space camera canvas causes problems that were not there when dealing with the ScreenSpace overlay mode, I now need to zero out the localPosition.z and set the localScale to 1 on all runtime prefabs that I add to the hierarchy.

    So anyway, any other thoughts of directions to try for capturing the UI?
     
  5. comixplay

    comixplay

    Joined:
    Sep 27, 2013
    Posts:
    104
  6. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    i 90% sure it a ordering issue in the render pipeline. The canvas doesnt emit its geometry at the proper times outside the render loop it will need to get fixed once a bug is filed.
     
  7. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    I saw Stephane had a case number 631091 already, so I haven't re-submitted..


    [edit: un-mangled name!]
     
  8. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    yup it also needs to get through QA to get to the devs so i think we're waiting on thats as well.
     
  9. fertigo

    fertigo

    Joined:
    Feb 15, 2014
    Posts:
    19
    I have the same problem, rendertexture not capturing the Gui.

    However I couldn't find an issue under number 631091. Is this an issue and is it registered, so I can vote and follow;)

    Or does anybody already have a solution?
     
  10. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    469
    same here....
    Using Unity4.6f3 the problem still exist....
    damn i need RT the uGui in my project.... just waited for final 4.6 and still can not ship
     
  11. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    @Muckel can you send me your project as well so i can test against it.
     
  12. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    469
    yes sure!
    see PM.
     
  13. cesarpo

    cesarpo

    Joined:
    Jun 8, 2013
    Posts:
    97
    Does this bug got fixed?
     
  14. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    hopefully in 4.6.2p1 should be out soon
     
  15. ruddonomy

    ruddonomy

    Joined:
    Mar 2, 2013
    Posts:
    1
    I just ran into this bug today and boy was I surprised to find that it had been fixed in a patch release released TODAY. 4.6.2p1 worked perfectly for me. What perfect timing :D
     
  16. davebuchhofer

    davebuchhofer

    Joined:
    Nov 9, 2007
    Posts:
    126
    Waiting patiently for it to hit 4.6.3 so I can have a webplayer :)
     
  17. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    :) Glad it works for you.
    Yea :( that might be a little bit yet as we usually have 4 patches between majour