Parallax only shows in one panel in my split screen game

Godot Version

4.2.2

Question

I have a 2d side scroller with split screen local multiplayer. I added a forest level, and setup ParallaxBackground and two ParallaxLayers to add depth. All is working as expected, but only in the first of four camera panels. The other three panels show no backgrounds, only the “main level” graphics.

Below is my split screen node tree and attached script. Happy to share anything else to help arrive at an answer.

extends Node

@export var viewports : Array[SubViewport]
@export var cameras : Array[Camera2D]
@export var nametags : Array[RichTextLabel]
@export var current_level_scene_path : String

var level_parent : SubViewport
var level : GameLevel

func _ready():
	level_parent = get_node("VBoxContainer/HBoxContainer/SubViewportContainer/SubViewport")
	load_level(current_level_scene_path)
			
			
			
func remove_current_level():	
	# Remove the current level
	level_parent.remove_child(level)
	level.call_deferred("free")



func load_level(scene_path):
	var level_resource = load(scene_path)
	level = level_resource.instantiate()
	level_parent.add_child(level)
	
	# load the signals that change levels
	level.load_forest.connect(load_forest)
	level.load_house.connect(load_house)
	
	for i in range(0,4):
		viewports[i].world_2d = viewports[0].world_2d
		viewports[i].size.x = get_window().size.x/2.0
		viewports[i].size.y = get_window().size.y/2.0
		nametags[i].text = level.players[i].PlayerName
		
		var remote_transform = RemoteTransform2D.new()
		remote_transform.remote_path = cameras[i].get_path()
		level.players[i].add_child(remote_transform)
	
	
	
func load_forest():
	remove_current_level()
	load_level("res://Scenes/forest.tscn")
	

func load_house():
	remove_current_level()
	load_level("res://Scenes/level1_house.tscn")

There is a note in the docs regarding viewports for ParallaxBackground: ParallaxBackground — Godot Engine (stable) documentation in English

Also, Godot currently doesn’t officially support having things show in one viewport but not another. There is a proposal to make this easier though.

“Note: Each ParallaxBackground is drawn on one specific Viewport and cannot be shared between multiple Viewports, see CanvasLayer.custom_viewport. When using multiple Viewports, for example in a split-screen game, you need create an individual ParallaxBackground for each Viewport you want it to be drawn on.”

GOLD MINE. Thank you for sharing this from the docs.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.