- Home /
Render GUI elements to off screen camera
I have a camera that I've assigned a render texture to, so it doesn't display on the main application window. Using the OnGUI() function doesn't render any GUI elements to this camera, but it does to my other cameras which are displayed on the screen. Is there a way to include this camera in displaying the GUI elements from OnGUI()?
so you want your GUI to be shown on your render texture? is that what you are after? Just clearing up the question.
Answer by Mathieujofis · Apr 30, 2014 at 10:08 PM
Figured out the issue. I just had to set the active RenderTexture
to my camera's target texture in OnGUI(), for example:
void OnGUI()
{
RenderTexture.active = myCam.targetTexture;
GUI.Box(new Rect(200.0f, 100.0f, 600.0f, 300.0f), "Test");
RenderTexture.active = null;
}
I seem to be having a similar problem with my attempts to draw gui to a render texture, I tried to use your solution, but it seems to have no effect. However, when I play my game in "non fullscreen" mode, and try to manually resize the window while the game is playing, I can see my gui elements flicker on the render texture during the re-size, and then disappear again when I stop re-sizing the window. I was wondering what sort of set up you were using in your scene to get this to work?
Any help would be greatly appreciated!
I was able to figure out a solution that seems to work. Since I was drawing my render texture to a surface that would then be drawn by a different camera, I had to set the first camera clearflags to "dont clear" and then manually clear the color buffer on this camera after the second camera had finished rendering the scene image, aka "OnPostRender".
Your answer
Follow this Question
Related Questions
Non-square camera preview 0 Answers
Change GUI.Button Texture on runtime 1 Answer
Drawing GUI on Editor Window Preview Render 0 Answers
OnGui Function help 1 Answer