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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Issue: screenshots of GUI elements with rendertexture

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

  1. WillemKokke

    WillemKokke

    Joined:
    Sep 6, 2014
    Posts:
    31
    it's still in 5.3.5f1 and 5.4.0b18, which screws google cardboard apps over, as everything is rendered to a RenderTexture.. Haven't found a workaround yet.
     
  2. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    HOLY F***

    HOW THE HELL UNITY

    Looking into alternative to OnRenderImage or a way to get the GUI elements from OnGUI /UGUI (without worldspace) into a RenderTexture...

    Some vague ramblings about using a coroutine..with F*** all example (sick of unity help documentation is S***. and doesn't provide direct link to reporting issues with it) and good luck trying this.. cus after you do, you wind up here finding out its a F***ing bug that hasn't been fixed in F***ing ages...
     
  3. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,516
    Wait... so this still hasn't been fixed?!?
     
  4. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    https://docs.unity3d.com/ScriptReference/WaitForEndOfFrame.html

    The png example works.. well not the "IEnumerator Start()" bit ...that doesn't.

    Anyway it it gets you a Texture2d with ui included.. which I guess is better than..

    Application.CaptureScreenshot()

    which encodes and saves the image final image with ui etc, taking ages, with not much option on anything.
     
  5. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    gui that isn't worldspace (which only works for ugui and not ongui) ..into a rendertexture.. nope
     
  6. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,986
    Works fine for me in 5.3.4f1. (not with OnGUI, obviously, but I doubt that will change). In fact, I have never had problem with it in any version of 5 that I am aware of. (though skipped a couple of the 5.2 versions).
     
  7. Thibault-Potier

    Thibault-Potier

    Joined:
    Apr 10, 2015
    Posts:
    206
    Hi
    So I was wondering why my UI did'nt show up in my screenshot, i first though it was because of OnPostRender() and finally i end up here.

    Soo ... am i f****** ?

    Code (CSharp):
    1. private void OnPostRender()
    2.     {
    3.         //Create a new texture with the width and height of the screen
    4.         Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
    5.         //Read the pixels in the Rect starting at 0,0 and ending at the screen's width and height
    6.         texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
    7.         texture.Apply();
    8.  
    9.         string path = Application.persistentDataPath + "/TEST.png";
    10.         byte[] imageBytes = texture.EncodeToPNG();
    11.  
    12.         //Save image to file
    13.         System.IO.File.WriteAllBytes(path, imageBytes);
    14.     }