Window with separate camera for scene

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

The scene hierachy

Basically, how would I get the Camera2D under Window to show Sprite2D? I want to show both nodes to both cameras at the same time, with different windows, but the only answer I’ve seen is to write a shader for it. Is that still the only solution, or have things changed?

I want a split screen effect, but with 2 windows at once.

Think of it this way: a window/viewport has ownership of its child nodes. How would you decide ownership if both windows had the same child node?
I don’t think this is a supported feature.

zhyrin | 2023-04-12 07:55

Well, I may not have worded it the best, but I mean to ask if there’s any way I can have the Window render the same scene as Node2D; essentially, a second camera for the same scene instead of having to render the whole thing again.

Vercte | 2023-04-13 00:06

A window can render its children.
You might be able to achieve what you want with viewports and viewport textures, but I can’t give any more concrete ideas.

zhyrin | 2023-04-13 11:41

Solved similiar demand by using this structure:

image

And then attaching this script to sub-window:
extends Window

@onready var main_window: Window = $“…”.get_window()
@onready var second_window: Window = $“.”
@onready var second_camera : Camera3D = $“…/SecondChar/Camera3D”

func _ready():
world_3d = main_window.world_3d
RenderingServer.viewport_attach_camera(second_window.get_viewport_rid(), second_camera.get_camera_rid())