godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.14k stars 21.19k forks source link

ViewportTexture must be assigned in code to be rendered in-game and does not render in the editor when reloading scene. #68787

Open InitialCon opened 1 year ago

InitialCon commented 1 year ago

Godot version

4.0 Beta 5

System information

Windows 10, Vulkan, Nvidia drivers version 516.94

Issue description

When assigning a ViewportTexture to a material it displays in the editor however, when the game is launched the ViewportTexture does not display correctly and only draws a solid purple color. Additionally, when the scene is closed and re-opened this same issue occurs. Expected behavior is that the texture displays the same in-game as it does in the editor. Assigning the ViewportTexture using GDScript circumvents this issue.

image Quad on the left has its texture assigned in GDScript, Quad on the right has its texture assigned in the editor.

Steps to reproduce

Create a SubViewport with a camera3d as a child. Set the SubViewport's update mode to always. (Update mode "When Visible" doesn't seem to work currently) Create a quad mesh with a standard material and set its albedo_texture to a ViewportTexture pointing to the SubViewport . Save the scene. Close and reopen the scene.

Minimal reproduction project

ViewportBugMRP.zip

Mikeysax commented 1 year ago

@InitialCon this is likely due to another bug where viewport textures of 512x512 do not render. If you change the resolution this should be resolved; to something like 514x514.

InitialCon commented 1 year ago

That bug has already been fixed in beta 5, I checked myself to confirm it and these two bugs are unrelated.

GrauBlitz commented 1 year ago

Same version, i also have the same problem. Everything renders fine in the editor and in game it is just purple all over.

EDIT: Also when i restart the editor the texture is also purple, until i remove it and add it again. This comes up as error in the console: Viewport Texture must be set to use it.

InitialCon commented 1 year ago

Yeah. My original theory was that Viewport textures aren't being set when the engine loads a scene but I didn't want to include speculation in the issue.

Mikeysax commented 1 year ago

This seems to be a contributing to an issue I'm experiencing in regard to ViewportTextures and setting them via tool scripts. Godot seems to not see them when the application loads initially. I have to close and reopen the scenes but then, certain scenes end up losing the shader uniform param values I'm setting as they reset to 0 or no value.

Rindbee commented 1 year ago

This issue is similar to #68088, see https://github.com/godotengine/godot/issues/68088#issuecomment-1321067723 for the cause of this issue.

addmix commented 1 year ago

I am still experiencing this issue in Beta 10. I believe this error may be related? image

InitialCon commented 1 year ago

I've found the cause of this issue. While the editor claims you need to make your material local to scene for it to display correctly and throws an error if you don't, you actually need to make the mesh that it's attached to local to scene as well to avoid this issue. Should this be changed or do we take the simple solution of changing the message that is displayed when you assign a viewport texture to reflect this?