Render a Canvas to RenderTexture?

Hi guys,
Is there any way to render a canvas to RenderTexture?

I want to render the entire screen to RenderTexture, so I’m using:

RenderTexture rt = new RenderTexture(x, y, 24);
foreach (Camera cam in Camera.allCameras)
{
cam.targetTexture = rt;
cam.Render();
cam.targetTexture = null;
}

But it doesn’t render the GUI…

(bump…)

Some more info … The Canvas is set to “Screen Space - Camera”
The camera is orthographic, and is showing the GUI in the editor and game view.
cam.redner() renders the skybox or solid color to the renderTexture, but not the GUI.

Does anyone have any idea? or should I file a bug?

As much as it saddens me to say this it’s likely a bug and you should file one. i’m going to guess that maybe it won’t get fixed for v1 but hopefully soon after

This can probably be worked around by using a screen space - camera UI and setting it to render from your specific camera (set to orthographic mode). The ‘overlay’ mode doesn’t go through the normal render pipeline so it’s not injected into a normal camera render.

He says he already is using ScreenSpace-Camera and it’s not working.

Can you actually make the overlay UI “go through a normal render pipeline”?
Is it possible to capture the UI somehow in a render texture and blit it to the scene behind? A feature like this would be great to enable post processing effects on a canvas.
Are we stuck using Screen Space - Camera UI in this case?

2 Likes

true. I want to find a way to directly render canvas to RenderTexture

I already did that succesfully. but not with manual rendering though. If the canvas is set to Screen Space - Camera and the Camera has a render texture assigned, this works quite well for me. Not sure what you want to achieve by manual rendering though, thats something I didn’t test for the UI yet.

1 Like

In my case, i need to render the canvas into one texture immediately. And then i don’t need this canvas anymore. It will be perfect if i can keep this canvas as prefabs in asset folder instead of the scene.

What i do now is that: I copy this prefabs into scene and create a camera with rendertexture. I call ResetAspect() ResetProjectionMatrix() Render(). And then delete the canvas and the camera. It doesn’t work quite well the size of the canvas is wrong. If i let those objects stay, then they can render a correct image in next frame.

Has someone solved this?

Bump?

I combine multiple cameras onto a single rendertexture before blitting to the screen, but my world space canvases are missing :frowning:

1 Like

Same problem… Unity5, trying to get some nice screenshots from a button press during gameplay… I have a single camera with canvas, screen space overlay gui, but the gui does not show up on the Camera.Render()
(also tried world-space and screen-space-camera) all with the same result… no gui rendered.
Any update to this problem ? bug ?

i think there is a backport request waiting to be processed to get his fixed.

Tested my world canvases in 3.5.0b6 and it seems to be fixed

Going to assume you mean 5.3.0b6 :slight_smile: but glad to hear hopefully the backport will land in 5.2 “soon”

2 Likes

Does this work because it seems like it still doesnt work

Cannot get the UI to render to a texture for me on 5.3.1f1 only seems to work with a World Space camera… not a screen spaced one :frowning:

Experiencing same problem with 4.6.9p3

Hi,

Any update on this issue? I’m using 5.3.2f1 and it’s not working.
Any suggested workarounds?

Regards,

Farooq

1 Like