0 votes

I have a 3d system that uses "mouseentered" and "mouseexited" 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.

Godot version 3.5.1
in Engine by (16 points)
edited by

1 Answer

0 votes

I've found the solution to my own question on this reddit post:
https://www.reddit.com/r/godot/comments/tx9x2b/a_guide_to_mouse_events_in_subviewports/

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

extends ViewportContainer
func _ready():
    set_process_unhandled_input(true)
func _input(event):
    # fix by ArdaE https://github.com/godotengine/godot/issues/17326#issuecomment-431186323
    for child in get_children():
        if event is InputEventMouse:
            var mouseEvent = event.duplicate()
            mouseEvent.position = get_global_transform_with_canvas().affine_inverse() * event.position
            child.unhandled_input(mouseEvent)
        else:
            child.unhandled_input(event)

Hope that helps anyone else with a similar issue.

by (16 points)

I found my answer.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.