I have a ViewportContainer node and I wish to pass the mouse event it receives to its Viewport child. From what I understand from the documentation the _gui_input() method catch the events and stop the propagation although I was wondering if it was possible to send the events anyway.

I've seen on another post here that it can be achieved with the Viewport.input() method although the lack of documentation makes it difficult to understand what it does.

I tried something like this anyway :

onready var viewport = $"Viewport"
    
func _gui_input(event):
	viewport.input(event)

In my viewport I have a child node Camera2D trying to catch those events with the _unhandled_input() method.

You can do it like this:

func _input(event):
	if viewport and is_inside_tree():
		viewport.input(event)
		
func _unhandled_input(event):
	if viewport and is_inside_tree():
		viewport.unhandled_input(event)

That's what I used on my game, so I know it works. I don't use _gui_input(), but it should work the same. Basically what this does is take the even from one layer and passes it to another layer (by default, the event will be consumed).

Omg I just realised I passed the events into the input() method and not the unhandled_input(), this is why it didn't worked.

It has to be the same function. So _unhandled_input would map to viewport.unhandled_input and so on.

Yes I am just not familiar with the underscore notation of virtual methods and your example made me figure it out. Thank you

7 months later