what purpose of double yield(get_tree(), "idle_frame") ?

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

Can you please tell what purpose of lines :

yield(get_tree(), "idle_frame")

I tried to comment these lines with symbol #. But not detected any visible difference in execution. If possible please give detailed description.

in example :

func _ready():
    viewport = get_node("Viewport")
    viewport_sprite = get_node("televizor")
    # Assign the sprite's texture to the viewport texture

    # Let two frames pass to make sure the screen was captured
    yield(get_tree(), "idle_frame")
    yield(get_tree(), "idle_frame")
    viewport_sprite.texture = viewport.get_texture()

your godot version?

volzhs | 2019-05-03 21:48

:bust_in_silhouette: Reply From: eons

In this case, it seems that it tries to wait a couple of (idle) frames before assigning a viewport to a texture, looks like code of a version 3.0-, since 3.1 all problems with ViewportTexture were (apparently) solved and you do not even need code, only if working on split screen in 2D.