Viewport on 3D mesh doesn't pass Input down the tree on Godot 4

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

I try to replicate a part of the following offical demo for viewport interaction
https://godotengine.org/asset-library/asset/127

For testing purposes I added

func _unhandled_input(event):
if is_mouse_inside:
	if event.is_action_pressed("middle_mouse"):
		print("middle mouse pressed")

It does work as expected.

I’m not able to apply the same to my Godot 4 project. How do I get inputs to work on nodes further down?

:bust_in_silhouette: Reply From: CodingLikeADuck

Appearently with Godot 4 subviewports don’t get inputs anymore, only when put into a subviewport container. This won’t work for me because I’m rendering it to texture in a 3D world.

A solution is to push the (unhandled) input to the viewport

func _unhandled_input(event: InputEvent) -> void:
 $subviewport.push_unhandled_input(event)

Remember to apply some filtering like if the mouse is above the viewport otherwise it’ll push down every input at any time.