Greetings,
Is there a way to render a scene to a texture, free the scene and then use the texture as image.
I have some custom GraphNodes. I want to generate preview images for each node automatically when the game starts. I want to use these textures as items in an ItemList. I tried the following:
The scene I am trying to render to a texture has the following hierarchy.

I have a script attached to an ItemList node in another scene (my main scene). In the ready method of the ItemList node I use gettexture to get the texture from the Viewport of the instantiated scene I wish to render to a texture and then I try to add an item to the ItemList using the texture I just created. This is the script I am using in the ItemList node:
extends ItemList
func _ready():
var scene = load("res://Scenes/Previews/Vector3NodePreview.tscn").instance()
var imageTexture = ImageTexture.new()
var image = scene.get_node("Viewport").get_texture().get_data()
imageTexture.create_from_image(image)
add_item(scene.get_node("Viewport/Node").title, imageTexture)
pass
The only way I got it to render to a texture was to have the ViewportContainer be a child of my main scene. Then the code above works. However, the ViewportContainer renders ontop of my main scene as well. If I set the Visible property to false of the ViewportContainer, then the texture becomes empty. If I make the ViewportContainer render behind it's parent, then touches stop working.
What am I doing wrong and how can I achieve the effect I desire?
To put it into more simple words: I want to render a single frame of a scene to a texture and then use that texture as am ItemList item.