Whenever I try to use a ViewportTexture (to get a 2D UI on a texture used in 3D), the texture kind of just works once, clears and then stops updating. I've checked out the "guiin3D" demo project which seems to work, but moving things around a bit and saving that eventually broke as well and I couldn't get it back to working.
An example of what I'm trying to do:
- Create an empty scene with a Spatial as root
- Create a Viewport as child, set size to 100, 100
- Create a Label with a the text "TEST" as child to the Viewport
- Do "Save Branch as Scene" on the Label to make a scene of it, let's call it "UI"
- Create a MeshInstance with a QuadMesh and a new SpatialMaterial
- Set the Albedo texture of the new material to a new ViewportTexture, and pick our Viewport
You should now see "TEST" (upside down) on the quad.
- Switch to the UI scene and just save it (ctrl-S)
- Switch back to the original scene, the quad will now be black
Inspecting the viewport texture shows it's 0x0, and in the output window it throws an error:
scene\main\viewport.cpp:106 - Condition ' !vp ' is true. returned: Size2()
Basically it seems like the ViewportTexture totally loses track of the Viewport, and at this point there's no going back except re-creating the ViewportTexture and the new one gets lost just as easily.
When in the "broken" state, if I clear the Viewport Path of the texture, click Assign and pick my Viewport again, I get this path:
"/root/EditorNode/@@5/@@6/@@14/@@16/@@20/@@24/@@25/@@26/@@42/@@43/@@50/@@51/@@6456/@@6322/@@6323/@@6324/@@6325/@@6326/@@6327/Spatial/Viewport"
Which... doesn't look very reasonable (and also obviously only works within the editor and, again, only until the UI scene is edited.)