Issue: screenshots of GUI elements with rendertexture

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:

                mainCamera.targetTexture = renderTextureFull;
                RenderTexture.active = renderTextureFull;
                mainCamera.Render ();

                Rect portion = new Rect(0f, canvasMinY, canvasSizeX, canvasSizeY);

                readingTextureFull.ReadPixels (portion, 0, 0);
                System.IO.File.WriteAllBytes (directoryPath + "/" + fileName + "_total.png", readingTextureFull.EncodeToPNG ());

                mainCamera.targetTexture = null;
                RenderTexture.active = null;

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.

its a Unity bug, we know about it but didnt have time to fix it for V1.

+1 on this please, I have had bugs raised against my editor extension ( Screenshot Creator | Utilities Tools | Unity Asset Store ) , from customers.

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

Thanks

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.

@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.

1 Like

it should be fixed in the next beta as well.

2 Likes

I appears this issue is still not fixed in 4.6.1f1. Can anyone confirm? Thanks.

I can :slight_smile:

It wont even make it to the next patch release :frowning: 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.

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

Is this fix in 4.6.1p5 ?

yea it should make it for p5 i think/hope

I have this same problem in 4.6.2 so looks like it hasn’t been fixed :frowning:

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.

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

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?)

should have been in as of 4.6.2p1

(I’m stuck with the webplayer, so I needed the full point release :slight_smile: )

then it should have been in 4.6.3 yes

4.6.3f1 - the bug is still here

I’m also experiencing this bug on 4.6.3p3