godot: ParallaxBackground not showing in secondary viewports
Godot version
v4.1.dev3.official [a67d37f7c]
System information
- OS: Windows 11
- Godot version: v4.1.dev3.official [a67d37f7c]
- Renderer: Vulkan
- Videocard: GTX1060
Issue description
When adding an extra viewport for a split-screen game and two camera’s the ParallaxBackground TileMap doesn’t show on the second viewport (All other nodes do show). In the player code I use these lines to assign the camera to the right viewport:
func _ready():
var viewport = get_node('/root/BugDemo/GridContainer/SubViewportContainer' + str(player) + '/SubViewport')
var game = get_node('/root/BugDemo/GridContainer/SubViewportContainer1/SubViewport/Game')
viewport.world_2d = game.get_viewport().world_2d
$Camera2D.custom_viewport = viewport
$Camera2D.make_current()
The ParallaxBackground TileMap only shows in the first viewport.
Steps to reproduce
The example project below demonstrates the issue.
Minimal reproduction project
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16 (11 by maintainers)
Thanks for taking the time to elaborate on this. I’ll be using a custom solution for parallax scrolling with multiple viewports.
Which functionality? Inheriting from Node2D doesn’t change any of it’s functionality, it works well.
yes
Thank you, can you please explain why it inherits from CanvasLayer? It’s the only node that inherits from that class in the engine. If it’s only for z-order the ParallaxBackground could be a child of CanvasLayer in the tree.
get_viewport().get_id() isn’t available on Node2D.
I think the issue is with CanvasLayer itself. It has a custom_viewport member, that may not work with multiple camera’s and viewports. I’ve replaced the ParallaxBackground with a CanvasLayer in the attached demo project and it also doesn’t show on other viewports.
parallaxissue.zip
I did a little digging and found a possible issue, the ParallaxBackground is inherited from CanvasLayer, and it doesn’t seem to pickup the right viewport. I made a little patch to make it inherit from Node2D instead and now it does show in all viewports, but the position is not correct and the set_layer(…) isn’t available. I’ve also noticed that the canvas layer items have a different camera group name: “__cameras_c” instead of “_cameras” but just changing that didn’t seem to work.