Viewport texture not showing.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jagc

I want to have a 2D art background in a 3D world.

I copied everything - all the codes and the properties from the 2D in 3D demo in the asset store but i can’t seem to translate it at all in my project.

This is my node structure

+ game (Node)
|-- (other nodes of the project here)
|-- viewportQuad (MeshInstance)
|-- Viewport
|   |-- background (2D Node scene)

< background 2D Node scene >

+ background (2D Node)
|-- sprite (Sprite)
|   |-- bgLayer1 (Sprite)
|   |-- bgLayer2 (Sprite)
|   |-- bgLayer3 (Sprite)
|   |-- bgLayer4 (Sprite)

I tried to extract the nodes of the background scene and made the sprites a direct child of the Viewport node but still no luck. I still don’t see anything.

This is the script i copied from the demo.

var viewport = get_node("Viewport")
viewport_set_clear_mode(Viewport.CLEAR_MODE_ONLY_NEXT_FRAME)

yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")

get_node("viewportQuad").material_override.albedo_texture = viewport.get_texture()

It’s basically 5 lines of code only so it’s supposed to be straightforward. What am i missing here?

print(viewport.get_texture()) or print_debug(viewport.get_texture()) doesn’t help. It just shows you something like a resource (i don’t know what it is.) Like: [ViewportTexture:1207]
^ Idk how to use that for investigating or debugging.

Maybe there is a different way of seeing a viewport’s texture to debug this?

My Env:
Godot 3.1.1

Demo Env:
Godot 3.0

Not even comments for this one? anyone?

jagc | 2019-06-20 01:19

:bust_in_silhouette: Reply From: TheHobHobbit

don’t know if this will fix your specific problem, but for me, I could only see the viewport texture if it was applied to a sprite, and if that sprite was within the visible bounds of the camera. my solution was to set “update mode” under “render target” in the viewport’s settings to “always” while it’s “when visible” by default. looks like you should be able to change that value in GDscript as well, so you can make your own decision on whether it’s “visible” or not. (render_target_update_mode)