The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Hello,

**Godot version:
3.2.1
OS/device including version:
Windows 10
Minimal reproduction project:
https://1drv.ms/u/s!Arug_xB8WkZQtFRNDgHJ-GwbbneK?e=PnlxAB**
I have scene MovingAndReparenting.tscn:

Spatial
-MeshInstance
-DirectionalLight
-Camera
-Spatial1
--Viewport
--MeshInstance
--Camera

I want to render Viewport content to ViewportTexture of first MeshInstace.

Unfortunately I have to move the node of Spatial1 to another place of the scene in space at the start function.

That's why the objects I render to Viewport are not its children at start. (Viewport is not a Spatial type, so they would not move to a new place in space).

After moving Spatial1 node to a new place and reparent child nodes to Viewport there is nothing projected from Viewport.

Script for that scene:

func _ready():

    # translate Spatial1 to new location
    master_node.set_translation(Vector3(100,0,0))

    # parent all nodes to Viewport node
    for N in master_node.get_children():
        # leave first node because it is a Viewport
            if N != master_node.get_child(0):
                var node = N
                master_node.remove_child(node)
                # translate also child nodes
                node.set_translation(master_node.get_translation())
                viewport_node.add_child(node)
                node.set_owner(viewport_node)


    # set viewport texturte to mesh node albedo
    mesh_node.get_surface_material(0).albedo_texture = viewport_node.get_texture()
    # update viewport path
    mesh_node.get_surface_material(0).albedo_texture.set_viewport_path_in_scene("/root/Spatial/Spatial1/Viewport")

But scene tree is correct in remote:

Spatial
-MeshInstance
-DirectionalLight
-Camera
-Spatial1
--Viewport
---MeshInstance
---Camera

Interesting thing is when i save scene to tscn from code:

var packed_scene = PackedScene.new()
packed_scene.pack(get_tree().get_current_scene())
ResourceSaver.save("res://my_generated_scene.tscn", packed_scene)

there is no children nodes of Viewport in that tscn file but in remote i see that nodes as children of Viewport

In that project i made also scene WithoutMovingAndReparenting.tscn where:

I place Spatial1 node and his child nodes to another place in scene in editor without any reparenting script operations.

Script for that scene:

extends Spatial

onready var viewport_node = get_node("/root/Spatial/Spatial1/Viewport")
onready var mesh_node = get_node("/root/Spatial/MeshInstance")

func _ready():
    # set viewport texturte to mesh node albedo
    mesh_node.get_surface_material(0).albedo_texture = viewport_node.get_texture()

And it that case Viewport works good.

Does anyone have any idea why this is happening?
How to deal with such a problem? Doesn't Viewport update the data correctly?

in Engine by (39 points)

For the record, this was cross-posted to https://github.com/godotengine/godot/issues/38950

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.