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

Button inside viewport not receiving input when Camera2D active #48368

Open
elektito opened this issue May 2, 2021 · 8 comments
Open

Button inside viewport not receiving input when Camera2D active #48368

elektito opened this issue May 2, 2021 · 8 comments

Comments

@elektito
Copy link

elektito commented May 2, 2021

Godot version:
3.3

OS/device including version:
Ubuntu 20.04

Issue description:
Button placed inside a Viewport receive mouse clicks normally, but when a Camera2D is active (whether Viewport is a child of the camera or not) the clicks won't register with the button at all.

Steps to reproduce:

  1. Create a new scene.
  2. Place a Camera2D, inside it a ViewportContainer, inside it a Viewport and inside that a Button.
  3. Set sizes appropriately
  4. Run and click on the button. The button reacts to clicks as normal.
  5. Make the Camera2D current. Run the scene again. Now clicking on the button has no effect at all.

The above just looks at the button's normal animation when clicked, but if you connect an event handler to the pressed signal of the button, you see that with the Camera2D current, the signal is not fired either.

Minimal reproduction project:
test-viewport-input.zip

@Calinou
Copy link
Member

Calinou commented May 2, 2021

See also #29570 and #35965. (Please check whether these issues are duplicates.)

@elektito
Copy link
Author

elektito commented May 2, 2021

These look very much like having the same root cause as my issue. Hard to be sure though. Also, I see that godotengine/godot-visual-script#39 mentions that for viewports "you have to calculate input offsets yourself", which I don't remember reading anywhere in the docs. Is that true? And if it is, with things like button events we don't directly control the offset calculation so there isn't much to be done.

@kleonc
Copy link
Member

kleonc commented May 2, 2021

Minimal reproduction project:
test-viewport-input.zip

Can't reproduce the issue. For me it works fine in both cases (Camera2D's current enabled/disabled). Windows 7, 3.3.stable.

Edit: as @elektito mentioned, after resizing the window the issue is present.

@elektito
Copy link
Author

elektito commented May 2, 2021

I use a tiling window manager (StumpWM) so when I run the game, it opens maximized by default. I tried the test project again in a "float group" which simulates a non-tiling window manager. Upon running, with the Camera2D current, the button seemed to work fine.

Then I resized the window and suddenly it stopped working. So looks like this only happens when the window is resized to something other than the default size. Maybe that's a clue. Not sure.

@elektito
Copy link
Author

elektito commented May 2, 2021

Also, looks like if I set the stretch mode to 2d and aspect to "keep", the button continues to work fine even after resize. Although I've got another non-minimal project of my own which seems to still have the issue even with stretch settings set to 2d/keep. That one's only tested in the tiling window manager.

EDIT: Tried that other project in non-tiling window manager and it still has issues. I can share it if helps, but it's a bit of a mess.

@Reneator
Copy link

Reneator commented May 3, 2021

2. Place a Camera2D, inside it a ViewportContainer, inside it a Viewport and inside that a Button.

It properly works for me if i order it like this: (Besides on resize)
image

Edit: Tested with your minimal reproduction project and found it doesnt work after resize despite of the different order that works in my game (im keeping the ratios, s a resize so i guess its a non-issue for me)

While playing around with resizing the window it seems that the button only registers the mouse~~ if its inside of some "invisible" square that moves around more/differently then the button on resizing the window~~

Edit2: its actually like the gui_input area of the button gets moved at a different rate than the visual button itself.
Viewport_Resize

@jonSP12
Copy link

jonSP12 commented Apr 4, 2022

Is there an upDate on the issue ?
if a button is inside a viewPort the mouse position is also showing on top left corner when zooming in / out. It only works with the camera zoom set to 1.

if ( wheel_up ):
	myCamera2D.zoom.x -= 0.05;
	myCamera2D.zoom.y -= 0.05;
	camY += 2.3;

	myCamera2D.zoom.x = clamp(myCamera2D.zoom.x, 0.05, 1);
	myCamera2D.zoom.y = clamp(myCamera2D.zoom.y, 0.05, 1);
elif ( wheel_down ):
	myCamera2D.zoom.x += 0.05;
	myCamera2D.zoom.y += 0.05;
	camY -= 2.3;

	myCamera2D.zoom.x = clamp(myCamera2D.zoom.x, 0.05, 1);
	myCamera2D.zoom.y = clamp(myCamera2D.zoom.y, 0.05, 1);
elif ( mouse_buttonMiddle ):
	myCamera2D.zoom.x = 0.3;
	myCamera2D.zoom.y = 0.3;
	#camY = -200;

@Sauermann
Copy link
Contributor

I have tested the MRP with v4.2.dev3.official [013e8e3] and I can no longer replicate the bug.
So I'm setting the milestone of this issue to v3.

@Sauermann Sauermann added this to the 3.x milestone Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants