Rendering image of scene as fast as possible ?

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

I am trying to get image of scene, which requires yield for a second or so.
However I wish to make it as fast as possible, how would I do that ?

This is the code:

$ViewportContainer/Viewport.add_child(node)
#yield(get_tree().create_timer(1), "timeout")
#yield(node, "tree_entered")

var imageTexture = ImageTexture.new()
var image = Image.new()
image.copy_from($ViewportContainer/Viewport.get_texture().get_data())
imageTexture.create_from_image(image)

$ViewportContainer/Viewport.remove_child(node)

Skipping a frame or two, doesn’t it work? To skip a frame use: yield (get_tree (), “idle_frame”)

estebanmolca | 2021-03-06 18:35

If I do yield idleframe 2 times it works. Does it still work if its ran on different computer (faster or slower…) ?

wildboar | 2021-03-06 18:39

I suppose that yes, the time between each frame can be slower or higher depending on the pc but at the end of the day it will always jump 2 frames

estebanmolca | 2021-03-06 20:38

Okay, great! Thanks you very much.

wildboar | 2021-03-06 20:44

:bust_in_silhouette: Reply From: wildboar

Adding yield idle_frame twice does the job.

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