[Viewport] Render a Node in multiple Viewports

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

For a splitscreen-game I want to render the game from each player’s perspective and arrange these renders next to each other on the screen. I tried to solve this based on the 3D-in-2D-Demo project: Each player has a camera within a viewport. Those viewports’ textures are rendered to sprites. But viewports are capturing, meaning they only render their (direct or indirect) child nodes. But I cannot make the game map a child of both viewports at the same time.

How can I tell the viewports to both render the map?

This is my node structure:

+ Game (regular "Node")
|-- Map (floor, walls etc.)
|-- Players (Spatial)
|   |-- Player 1 (Spatial)
|   |   |-- KinematicBody
|   |   |-- Viewport
|   |        |-- Camera
|   |-- Player 2 (Spatial)
|       (same as Player 1)
|-- Sprite 1
|   (using Viewport of Player 1 as texture)
|-- Sprite 2
    (using Viewport of Player 2 as texture)

I also tried following this tutorial: https://www.youtube.com/watch?v=WhCQABLmEv0 but it’s for Godot 2 and I cannot get it to work with Godot 3.

I am using Godot 3.0.5 both on Linux x64 and Windows x64.

After grepping through the example projects for “Viewport” I found that the “Interactive Cubes” demo seems to do kind of a splitscreen-implementation. It seems to duplicate the whole scene, but only as a linked Scene, so I guess that is okay and good style? (usually I do OOP or functional; node-based design is still quite new to me)

Anyway, I’ll fiddle around and let you know if I get it working.

ConnyOnny | 2018-07-27 13:32

:bust_in_silhouette: Reply From: ConnyOnny

Okay, I was totally on the wood way with everything concerning Viewports.

Viewports render the whole scene, not only their children

The problem was that I had the camera as a child of the player kinematic body to be able to set its position relative to the player. When I replaced the Camera by a Viewport with a Camera, the relative spatial transformation got lost; I suspect because Viewport is not a Spatial node and that makes it lose relative positioning. This also explains why the tutorial video had to create dummy cameras under the car node and on every step update the real camera’s (the one in the Viewport) transform with the global transform of the dummy camera.

Viewports as non-Spatial-nodes prevent relative positioning of child nodes to parent nodes of the Viewport.

Finding the source of my problem has taken me several days now. There really should be at least a hint in the Viewport doc about this. Better even: The editor could display a warning sign, if a hierarchy of Spatial nodes is interrupted by a non-Spatial Node because this loses the ability to position relatively to the parent Spatial.

There really should be at least a hint in the Viewport doc about this.

Better tell the documentation team about that one.

Ertain | 2018-07-29 18:00