I have an Node2D called CameraIcon with two Sprite2Ds and an Area2D with a simple rectangle CollisionShape2D. The goal is to be able to click them or hover them to change which sprite is displayed. When I run just the 2D scene I am able to click and fire the event just fine but when it is in a SubViewport it seems to eat the input and not even fire the event.
I downloaded the “GUI in 3D Viewport” demo from the Godot engine asset library and that provided me with the math and methods to pass coordinates through events when the SubViewport is mapped to a ViewportTexture on a mesh by using an Area3D. The Control nodes all function correctly but I have yet to get Area2D nodes to respond using this formula.
The SubViewport has the following enabled:
Physics > Object Picking
Handle Input Locally
GUID > Embded Subwindows
Is there something I am doing incorrectly or is this not possible in Godot?
I have just tried to receive physics-picking input events in an Area2D node in the SubViewport of the demo project and I was able to do so.
So it is likely, that there needs to be an adjustment made in your project files, but I didn’t see any obvious problem in your screenshot.
One of the problems, people experience in these situations, is that a Control-node takes precedence for handling input events, so perhaps you also have a Control node in the SubViewport, which has as mouse_filter either of the values Pass or Stop.
If you could share your project file, it would be easier to pinpoint the problem.
func _mouse_entered_area() -> void:
is_mouse_inside = true
node_viewport.notification(NOTIFICATION_VP_MOUSE_ENTER) # this line is new
func _mouse_exited_area() -> void:
node_viewport.notification(NOTIFICATION_VP_MOUSE_EXIT) # this line is new
is_mouse_inside = false