How to troubleshoot mouse input not being recognized by items in a custom viewport.

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

I have a 3d system that uses “mouse_entered” and “mouse_exited” a lot. I have a 2D ui overlay and inside of that I just added a viewport to render a single inventory item in a 3d view that covers most of the screen until closed. I want to be able to get info on the item in this viewport by hovering over it and sometimes interact with the item through mouse clicking too.
However, no item rendered to the viewport reacts to the mouse.

I’m new to all this, but searching leaves me without further actions to take to remedy this. Here’s what I’ve done so far:

  • I made sure that the viewport is a child of a ViewportContainer.
  • I moved the ViewportContainer to the root of the 2d ui overlay scene.
  • I tried all the mouse filters in the ViewportContainer and all parent nodes.
  • I made sure that the viewport’s GUI → Disable Input is turned OFF.
  • I tried turning of Transpareng BG (it should ultimately be on).

Are there any further actions anyone can think to try to resolve this issue?
Thanks for any help you can provide.

:bust_in_silhouette: Reply From: violgamba

I’ve found the solution to my own question on this reddit post:

Specifically this script, added to the ViewportContainer caused things to work for me:

extends ViewportContainer
func _ready():
func _input(event):
	# fix by ArdaE
	for child in get_children():
		if event is InputEventMouse:
			var mouseEvent = event.duplicate()
			mouseEvent.position = get_global_transform_with_canvas().affine_inverse() * event.position

Hope that helps anyone else with a similar issue.

I found my answer.

Asidert | 2022-12-27 09:22