0 votes

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
            raise()
        else:
            is_drag = false
        get_tree().set_input_as_handled()

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

child script:

extends 'res://parent_scripts/equipment.gd'

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.set_shape(CircleShape2D.new())
    $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):
    ._physic_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.set_script(load("res://scripts/shields.gd"))
    child.init('shield', 2, 5, 0, 0)
    child.position = Vector2(50, 50)
    add_child(child)
Godot version 3.2.3.stable.official
in Engine by (159 points)
edited by

1 Answer

+1 vote

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 mousefilter to MOUSEFILTER_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". https://docs.godotengine.org/fr/stable/classes/class_control.html?highlight=Control#enum-control-mousefilter

by (639 points)

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

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 
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.