Control nodes in SubViewport not handling events

Godot Version

4.4

Question

I have a button in my scene tree which is only handling events from the main viewport. The tree is roughly

- Button
- CanvasLayer
    - SubViewportContainer
        - SubViewport
            - Camera2D 

Button is on multiple visibility layers. The main viewport is looking at layer 1, subviewport at layer 2. Button input is handled fine from main viewport (i.e. can be clicked) but not from the subviewport.

I can see using either the debugger, or a _input/1 call that the subviewport is receiving events okay, but these are not being received by the button. I.e., attempting to click the button through the subview port shows ‘clicked controlled’ as SubViewportContainer, where as through the main viewport shows Button.

Any ideas?

My assumption would be, that by “Button is on multiple visibility layers” you mean, that you assign the root world_2d to the SubViewport, as in:

extends SubViewport


func _ready() -> void:
	world_2d = get_tree().root.world_2d

In that case this will not work, because the Button is a GUI element and not part of the world_2d.
What would work, is if you use Node2D-based nodes (like Area2D), since they are part of the world_2d and can be interacted with from the root viewport and from the SubViewport.