Control not consuming MouseEntered signal for underlying Area2D Nodes
Asked Answered
T

5

0

How can I ignore the MouseEntered and MouseExited signals for any Area2D nodes that are under an UI element? I know I can use the _UnhandledInput method to ignore e.g. mouse clicks on an object that is under a Control node, but the Controls don't seem to consume the MouseEntered and MouseExited signals even if Filter is set to Stop.

Transmarine answered 15/11, 2023 at 18:12 Comment(0)
D
1

I tried it in 4.1.1 and saw your issue happen. I was not able to devise a quick workaround, as even deliberately eating the event in the control with get_viewport().set_input_as_handled() still let the enter and exit events through. Tried it in 4.1.3 and it occurs there as well. It seems likely that the issue was fixed only for 4.2.

Danczyk answered 16/11, 2023 at 22:54 Comment(0)
D
0

That seems unusual. Those signals should be blocked. It sounds like you have the correct setup with Filter set to Stop. I just tested it out. This is my scene:

and this is the entire .tscn file:

[gd_scene load_steps=6 format=3 uid="uid://dxukvek8fqn5q"]

[ext_resource type="Texture2D" uid="uid://bqori034vw85r" path="res://icon.svg" id="2_tdqg2"]

[sub_resource type="GDScript" id="GDScript_g8evc"]
script/source = "extends Area2D

func on_mouse_enter() -> void:
	print(on_mouse_enter)

func on_mouse_exit() -> void:
	print(on_mouse_exit)

func _mouse_enter() -> void:
	print(_mouse_enter)

func _mouse_exit() -> void:
	print(_mouse_exit)

func _input_event(viewport: Viewport, event: InputEvent, shape_idx: int) -> void:
	print(_input_event)
"

[sub_resource type="Gradient" id="Gradient_pq4ix"]

[sub_resource type="GradientTexture2D" id="GradientTexture2D_55a8y"]
gradient = SubResource("Gradient_pq4ix")

[sub_resource type="RectangleShape2D" id="RectangleShape2D_ogng8"]
size = Vector2(63, 64)

[node name="Node2D" type="Node2D"]

[node name="Area2D" type="Area2D" parent="."]
position = Vector2(263, 167)
script = SubResource("GDScript_g8evc")

[node name="Sprite2D" type="Sprite2D" parent="Area2D"]
texture = SubResource("GradientTexture2D_55a8y")

[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource("RectangleShape2D_ogng8")

[node name="TextureRect" type="TextureRect" parent="."]
offset_left = 205.0
offset_top = 106.0
offset_right = 333.0
offset_bottom = 234.0
mouse_filter = 0
texture = ExtResource("2_tdqg2")

[connection signal="mouse_entered" from="Area2D" to="Area2D" method="on_mouse_enter"]
[connection signal="mouse_exited" from="Area2D" to="Area2D" method="on_mouse_exit"]

Aside from icon.svg it's entirely self-contained. When I move the mouse across the Area2D, I don't get ANY of those print statements. Then if I make the TextureRect invisible and move my mouse across the Area2D, I get all of them.

Either something is weird with your setup or it is a bug in your Godot version. What version does it show when you go to Help/About Godot?

Danczyk answered 15/11, 2023 at 19:43 Comment(0)
T
0

Danczyk
Hi, my version is v4.1.2.stable.mono.official [399c9dc39]

I recreated your scene with C# as in my game and got the same weird behaviour as before

The script of my Area2D node:

using Godot;

public partial class Test : Area2D
{
    public override void _Ready()
    {
        MouseEntered += () => GD.Print("Mouse entered"); 
    }
}

I then tried your scene without changing anything and actually got the same behaviour there: the debug message is printed even if the TextureRect is visible

Transmarine answered 16/11, 2023 at 14:35 Comment(0)
D
0

Hm I'm on 4.2.beta, might be something that got fixed but I'm not seeing the specific issue on github. I'll try later to see if it happens to me in 4.1

Danczyk answered 16/11, 2023 at 19:47 Comment(0)
D
1

I tried it in 4.1.1 and saw your issue happen. I was not able to devise a quick workaround, as even deliberately eating the event in the control with get_viewport().set_input_as_handled() still let the enter and exit events through. Tried it in 4.1.3 and it occurs there as well. It seems likely that the issue was fixed only for 4.2.

Danczyk answered 16/11, 2023 at 22:54 Comment(0)
T
0

Danczyk
Okay, I think I’ll just migrate to the newer version. Thanks

Transmarine answered 17/11, 2023 at 7:26 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.