system
1
|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
qazwsx |
|
Old Version |
Published before Godot 3 was released. |
I have a structure with Viewport:
I want to have object (like button) in viewport which allows me to click on it. How I can achieve this?
The events to not work for the Button here
system
4
|
|
|
|
Reply From: |
mollusca |
You can forward the input events from one of the Viewport
’s parent nodes with the Viewport.input(InputEvent local_event)
function. In the parent node:
onready var viewport = get_node("Viewport")
func _ready():
set_process_input(true)
func _input(event):
viewport.input(event)
You might also have to offset the position of mouse events if your ViewportSprite
isn’t in the top left corner.
Very nice tip. In the past I set up a variable inside the sub-viewport, and had the parent viewport pass along the information I needed.
avencherus | 2017-11-30 10:01
I got it to work with a ViewportContainer:
set the ViewportContainer mouse settings to ignore
then forward the UNHANDLED input to the viewport
onready var viewport = get_node("Viewport")
func _ready():
set_process_input(true)
func _unhandled_input(event):
viewport.input(event)
I hope i prevent someone the 4 hours of desperately looking everywhere for a fix i spent
Thanks for this code snippet!!! It did save me!
darkmarmot | 2021-01-06 19:59
You save my life
The_Moye | 2021-07-20 16:02