Delay in SubViewport Rendering?
I've been using Godot to run some image processing with shaders - place an image into a TextureRect in a SubViewport, assign the shader, force render, then take the resulting image for further processing.
It works, but there's an issue. I'm using these functions (as members of a subviewport class):
func render():
var scene_tree = self.get_tree()
var root_viewport = scene_tree.root.get_viewport_rid()
RenderingServer.viewport_set_active(root_viewport, false)
# Render SubViewport once
RenderingServer.frame_post_draw.connect(_frame_drawn)
RenderingServer.viewport_set_update_mode(self.get_viewport_rid(), RenderingServer.VIEWPORT_UPDATE_ONCE)
RenderingServer.force_draw()
await RenderingServer.frame_post_draw
# Enable main viewport again
RenderingServer.viewport_set_active(root_viewport, true)
func _frame_drawn():
RenderingServer.frame_post_draw.disconnect(_frame_drawn)
processed_image = self.get_texture().get_image()
The problem is with the get_texture().get_image() function. It doesn't actually return a usable image when called here. It returns an image, but it's black, not actually a rendered image yet. As a result, that _frame_drawn() function doesn't actually work.
Instead, I can access the data manually using get_texture().get_image() - but only after about 10ms. I've used a timer to test. The image is always blank (black) until the minimum delay has passed.
I expected that force_draw() and await frame_post_draw() would mean the subviewport image should be rendered and ready for access.
What exactly is going on here? And is there any way to fix this issue so that I can get the properly rendered images immediately?
Posted Oct 28, 2025, 9:39 PM UTC