Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When set as "render target", viewport blocks input for children nodes #8419

Closed
tr0q opened this issue Apr 15, 2017 · 7 comments
Closed

When set as "render target", viewport blocks input for children nodes #8419

tr0q opened this issue Apr 15, 2017 · 7 comments

Comments

@tr0q
Copy link

tr0q commented Apr 15, 2017

Godot 2.1.3
(can be quickly tested with the "3d in 2d" demo)
Set up viewport as render target, add child with script that uses _input or _unhandled_input and try print event - nothing will happen. With "render target" disabled this issue won't appear.

@SolarMongoose
Copy link

This might be sort of by design?

Viewports have a method called "input(local_event)"
http://docs.godotengine.org/en/stable/classes/class_viewport.html#class-viewport-input
(and there's also one for "unhandled_input(local_event)"
which just... propogates the event...

So the simplest way to use it would be

extends Viewport


func _ready():
	set_process_input(true)
	set_process_unhandled_input(true)


func _input(event):
	input(event)


func _unhandled_input(event):
	unhandled_input(event)

Which should be enough if you only need key/button presses.
If you need mouse or screen touch events then you'll probably need to do some sort of position correction on the events to make them work right.

@tr0q
Copy link
Author

tr0q commented Apr 25, 2017

So the simplest way to use it would be

extends Viewport

func _ready():
set_process_input(true)
set_process_unhandled_input(true)

func _input(event):
input(event)

func _unhandled_input(event):
unhandled_input(event)

Doesn't work for me, children still don't receive input.

@SolarMongoose
Copy link

Oops. I thought I had made it work like that, but you're right, it doesn't.

Turns out the way I had gotten it to work was by catching the input in a different node (specifically the ViewportSprite I was displaying the viewport on, if that's important).

So you set_process_input(true) in this other node, then call
get_node("path/to/Viewport").input(event)

Tried in 2.1.3. Should work. Hope I helped... at all.

@tr0q
Copy link
Author

tr0q commented Apr 28, 2017

Thanks, it works. But I wonder why it has to be like this.

@reduz
Copy link
Member

reduz commented Apr 28, 2017 via email

@kubecz3k
Copy link
Contributor

kubecz3k commented Apr 7, 2018

I'm revisiting old issues, closing since this is not a bug.

@kubecz3k kubecz3k closed this as completed Apr 7, 2018
@kubecz3k kubecz3k removed this from the 2.1 milestone Apr 7, 2018
@jonSP12
Copy link

jonSP12 commented Apr 4, 2022

It has something to do with camera...
It only works if the camera zoom is at maximum size ( default 1280x720 )

If the camera is somewere in the level follwing the player... or zoomed at 0.5, the button coordinates inside the viewPort get passed somwere around the topLeft corner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants