Transforming attached scene (as a child node) does not affect on it's Viewport and Camera

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

Consider following scenario:


- Main
    - . . .
    - Enemy1
    - . . .
    - CanvasLayer
        - . . .
        - Enemy1Sprite


- Enemy
    - . . .
    - BlueCube
    - Viewport
        - GreenCube
        - Camera

If you translate Enemy1 node on Main scene (which contains BlueCube, GreenCube, Viewport and Camera), you can see that BlueCube just move.

This scenario (a scene which has a individual Viewport and Camera inside) is useful when we want multiple camera that following multiple objects (which may we don’t know how many them), then each node’s viewport projected to separate Sprite (using ViewportTexture)

Here is a demo project (a split-screen demo):

:bust_in_silhouette: Reply From: Zylann

This is normal. First of all, Viewport is not a spatial node, so even if any of its parent or grandparent moves, the transform will not be propagated. This is also true for Node, Node2D or Control as well.
Second, Viewport can have its own world, so it would not make sense to move its children automatically.
So to accomplish what you want, you should use a RemoteTransform as child of your viewport, and put objects you want to sync under it. Then connect the RemoteTransform to the root of the enemy. That, or write a script doing the same thing.

On the above project I implement what you say, but I don’t know why RemoteTransform does not work as expected and what you describe. Here is what I implement:

- Player
    - BlueCube
    - . . .
    - Viewport
        - RemoteTransform
            - GreenCube
            - PlayerCamera

and Remote Path property of RemoteTransform attached to Player node. But when I transform Player node (which is named Enemy in Main scene by mistake!) still BlueCube just move.

Generally, what you suggest for this scenario which we have multiple following camera that we want to see all of them at once?

siamak-s | 2019-08-12 13:22

If RemoteTransform node replaced with a Spatial node, a simple following line could sync Viewports child nodes transforms with root node (Player) transforms:

func _physics_process(delta):
	$Viewport/Spatial.transform = transform

But is that performance acceptable? Isn’t there a better way for this scenario?

siamak-s | 2019-08-12 13:54

This is basically what RemoteTransform does, and difference in performane is negligible. You could make it more efficient by caching $Viewport/Spatial in a variable though.

I don’t know what’s going on with the RemoteTransform, it should have worked.

Zylann | 2019-08-12 18:55