mouse entered and mouse exited signals

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Timofey

I solved this problem, I forgot that the input does not work on top of the gui

i am trying to connect these signals but they are not being called

this script is the parent script of another script that connected to the node

extends Area2D

var is_drag := false
var mouse_entered := false

func _ready() -> void:
    utils.assert(connect('mouse_entered', self, '_on_mouse_entered') == OK)
    utils.assert(connect('mouse_exited', self, '_on_mouse_exited') == OK)

func _on_mouse_entered() -> void:
    mouse_entered = true

func _on_mouse_exited() -> void:
    mouse_entered = false

func _unhandled_input(event):
    if event is InputEventMouseButton and mouse_entered:
    	if event.is_pressed():
	    	is_drag = true
	    	is_drag = false

func _physic_process(_delta: float) -> void:
    if is_drag:
    	position = get_global_mouse_position()

child script:

extends 'res://parent_scripts/'

var physical_defence := [0, 1]
var magic_defence := [0, 1]

func init(init_name, init_min_physical_defence, init_max_physical_defence, init_min_magic_defence, init_max_magic_defence) -> void:
    name = init_name
    physical_defence[0] = init_min_physical_defence
    physical_defence[1] = init_max_physical_defence
    magic_defence[0] = init_min_magic_defence
    magic_defence[1] = init_max_magic_defence

    $Sprite.set_texture(load('res://sprites/%s.png' % name))
    $CollisionShape2D.shape.set_radius($Sprite.texture.get_width() / 2)

func get_passing_damage(input_physical_damage: int, input_magic_damage: int) -> Array:
	var physical_passing_damage := input_physical_damage -    global.get_random_int(physical_defence[0], physical_defence[1]) as int
	if physical_passing_damage < 0:
    	physical_passing_damage = 0
    var magic_passing_damage := input_magic_damage -     global.get_random_int(magic_defence[0], magic_defence[1]) as int
    if magic_passing_damage < 0:
    	magic_passing_damage = 0
    return [physical_passing_damage, magic_passing_damage]

func _physics_process(delta):

through this script, the script connects to the node

extends Panel

var item

func _ready() -> void:
    var child := load("res://objects/item.tscn").instance() as Object
    child.init('shield', 2, 5, 0, 0)
    child.position = Vector2(50, 50)
:bust_in_silhouette: Reply From: MrEliptik

Juste to clear the confusion for others: by default, a control node will capture the mouse. You can alter this behavior by setting the mouse_filter option to MOUSE_FILTER_IGNORE or MOUSE_FILTER_PASS. You can set it in the editor, or by code.

From the docs: “Sets mouse_filter to MOUSE_FILTER_IGNORE to tell a Control node to ignore mouse or touch events. You’ll need it if you place an icon on top of a button”. Control — Documentation de Godot Engine (4.x) en français

But where/how do I set the variable to that value?

creesee | 2023-02-24 17:08

You set it on the control node itself.

Let’s say you have a ColorRect taking the whole screen and you have a button behind it.
The button doesn’t receive inputs because of the colorRect. So on this node, you go under Mouse and there you can set the filter you want. You can also do it through code

$ColorRect.mouse_filter = MOUSE_FILTER_IGNORE 

MrEliptik | 2023-02-28 08:20