0 votes

I'm working on a chess clone. There is a Board node of type VBoxContainer with 8 children holding the board's rows of type HBoxContainer, and each row has 8 children that are instances of a custom Square scene. I want to use the onBoardguievent signal / function to make sure it's code is only ran when mouse input happens within the Board. However, the function does not run at all.

This is the script for the Board:

extends VBoxContainer

var hovered_square : Node
var clicked_square : Node
var held_piece : Resource
onready var Cursor : Node = get_parent().find_node("Cursor")

# Connects each square's mouse_entered signal to Board
func _ready():
    for y in 8:
        var row : Node = get_node(str(y + 1))
        for x in row.get_child_count():
            var children : Array = row.get_children()
            children[x].connect("mouse_entered", self, "_on_Square_mouse_entered", [children[x]])

func _on_Square_mouse_entered(square):
    hovered_square = square
    print("entered " + hovered_square.name)

func _on_Board_gui_input(event):

    if event is InputEventMouseButton:
        if event.button_index == BUTTON_LEFT:
            clicked_square = hovered_square
            held_piece = clicked_square.piece
            print("clicked " + clicked_square.name + ", holding " + held_piece.name)

Is there a way to get onBoardguievent to work like I want, or should I take a different approach to implementing this feature? Also, feedback on general code style / structure is welcome if you are willing to provide it :)

Godot version 3.4.4
in Engine by (88 points)

1 Answer

0 votes
Best answer

Got a solution!

The Square's mouse_filter (under Mouse in Inspector) was set to Stop, which prevented the InputEvents from ever reaching it's parents. Changing this to Pass fixed the issue.

by (88 points)
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.