Passing input through a Viewport to Area2Ds

Godot Version

4.2 stable mono official


I’m porting my game from 3.5 to 4.2 and everything is working fine except for one (big) problem: I render my game in a Viewport in 3.5, and many of the objects in my game have Area2D’s attached to them to detect mouse hovers and clicks. So I’ve always faced this issue of how to pass the input through the viewport.

What ended up working for me in 3.5 was

  • On the Viewport, mark it for Object Picking: Yes
  • In the Viewport’s parent, a Control, mark it Filter: Pass
  • In the Viewport’s parent, a Control, add the following code:
	public override void _Input(InputEvent @event) {

This isn’t working in 4.2. According to the debugger, no one is detecting any clicks when I click in the space represented by t he parent Control / the Viewport under it.

What’s the right way to get Area2Ds and other things to receive input events when inside a Viewport in Godot 4.2?

If the viewport is a direct child of a SubViewportContainer, then the SubViewportContainer automatically propagates InputEvents to the viewport.

If the viewport is not a direct child of a SubViewportContainer, then you need to use the function push_input to propagate input events to the viewport.

See Viewport — Godot Engine (4.2) documentation in English

1 Like

Thank you so much, that did the trick. PushInput was what I was looking for. I had stumbled into PushUnhandledInput, which didn’t work, but failed to notice PushInput. Thanks again!!!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.