I’m trying to render OnGUI elements into a RenderTexture to be displayed on a 3D object, similar to what is described here and here.
The proposed solution describes setting RenderTexture.active to a camera’s target RenderTexture, then null afterwards. I have also tried getting/resetting the active RT with a “tempRT” variable as described, though it’s null anyway.
I am seeing strange and inconsistent results.
Mainly, it doesn’t work. I have a Camera with a GUILayer and a target RenderTexture, with a script doing OnGUI stuff on it. Another main camera (which does not have a GUILayer on it) is looking at a plane with the other camera’s target RenderTexture on it.
The GUI element does not appear in the RenderTexture.
BUT, strangely, I happened to notice that while I resize the editor game window, the GUI element WILL appear, flickering, as the window is resized. Also, even if the GUILayer on the gui camera is disabled/removed, this flickering GUI element is rendered. I have also seen some very inconsistent behaviour in terms of the GUI element appearing (or not) in the scene’s camera preview window, and/or appearing (or not) in the scene window. Very inconsistent. The closest I’ve gotten is it appearing on the plane in the scene window but not the game window. But after changing some things this went away as well. Now, it is back to the previous settings, and yet not appearing in the scene window, except while resizing the game window. Inconsistent.
It seems like it’s close, and it seems like it should work, but it’s not quite there. And the inconsistent behaviour is suspicious, esp, the way it is rendered while resizing, rendering when no camera has a GUILayer, reverting changes does not get back old behaviour, etc. I’ve tried mucking around with render paths, camera depths, various OnRender() type events, different clear flags, doing it only on Repaint event, etc. No joy. Too bad, too, cause while resizing the game window, it’s doing exactly what I want.
Anybody got this to work? Is there a trick to it?