godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.01k stars 21.17k forks source link

Area2D's don't receive input from Subviewports #97267

Open SubSage opened 1 month ago

SubSage commented 1 month ago

Tested versions

Tested in v4.3.stable.official [77dcf97d8]

System information

Godot v4.3.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated AMD Radeon RX 6800 XT (Advanced Micro Devices, Inc.; 32.0.11037.4004) - AMD Ryzen 9 5950X 16-Core Processor (32 Threads)

Issue description

Area2d nodes aren't getting any input when they're inside a subviewport. Handle input locally, pickable, monitorable, all correctly set to on. Pushing all input events into the scene and nothing; First discovered in my current game where I'm rendering 2d scenes via subviewports in 3d. Decided to test in purely 2d, same issue.

Made a test project to show side by side, area2d receives no input while a control node works fine.

Steps to reproduce

Have a 2d scene with area2d inside of it set to handle input (printing out all inputs on input_event signal as example). Put this 2d scene inside a viewport and those inputs aren't being received, ie, nothing will print out.

The purely 2d scene can be run alone and can be shown to work fine.

image image

Minimal reproduction project (MRP)

guitest.zip

SubSage commented 1 month ago

Went ahead and ran a test on that project just now in v4.4.dev2.official [97ef3c837] Same issue, area2D isn't getting anything.

Also I did triple check the options (pickable, phsyics object picking, etc) in both versions. I think in the zip of the MRP I left one of those settings off by accident.

I also tested just now in v4.2.2.stable.official [15073afe3] It works as expected there! Able to detect mouse over area and control perfectly fine, as well as all the other mouse inputs.

Decided to try the other versions and pint point.

Bug NOT present in v4.3.dev2.official [352434668] v4.3.dev3.official [36e943b6b] v4.3.dev4.official [df78c0636]

Bug present in v4.3.dev5.official [89f70e98d]

AThousandShips commented 1 month ago

SubViewports don't receive input when in a ViewportTexture, see:

A ViewportTexture is just a resource that can be used multiple times, it doesn't handle input but just draws the viewport. You need to pass the input manually with push_input, see this demo for some ways to do this

Keeping this open to document this more clearly (though it is already documented here), but there's no bug here

SubSage commented 1 month ago

That demo is only for Control nodes, not 2D nodes. That's how I started my current project in fact. But now that I'm trying to add Area2D's, issue..

You say I need to use push_input, I read that as a way to achieve the desired effect but that's exactly what I'm showing in the screenshots and in the MRP. I push all input events to the subviewport but the mouse entered signal doesn't get fired. Am I misunderstanding something? I'm pushing the input events manually and yet my area2D doesn't receive anything.

In the demo you link, I tried adding area2D's with shapes, set all the correct options on (handle input local, pickable, etc). No input on the area2d; If I make a subviewport container, put the subviewport into it, update script references, then the area2d receives input, but now we have the issue of the container rendering the subviewport directly to the screen... which the project aims to avoid. I want to render this screen to the designated mesh, as if it were a small window into another game, but also have proper input handling in it.

Sorry if my questions are beyond scope of the issue discussion, I just feel as though the intended route here isn't correct. The option of A) push inputs, doesn't work; B) Use viewportContainers defeats the purpose of rendering to specific area instead of directly to the screen.

I want to believe option B is the intended route and that I'm missing some steps I've missed.

AThousandShips commented 1 month ago

The pushing inputs is tracked here:

Let's focus here on the fact that viewports don't get input when used as a texture, which is intentional (or rather an obvious limitation) which should be documented a bit further than it already is

SubSage commented 1 month ago

That's basically the same setup I have, perfect. Thank you!

I had only found issues/links that were already closed, hadn't seen this one in particular. I'll keep an eye on that one. So it seems push_input is the intended solution, but is currently bugged. I'm happy knowing this and waiting for the fix for now.