Need help debugging code

Godot Version

4.4

Question

Hey, I’m making some highlighting logic for my cards in my game that I’m making, but the code doesn’t seem to be running, and I’m not sure as to why.

This snippet of code is part of my hand script, which keeps track of all the cards and the related functions to them. I am connecting the mouse_entered and mouse_exited signals from my card scene to the handle funcs but whenever my mouse enters the cards, nothing happens. Testing my mouse enter and exit in the card scene does work however, so I’m no longer sure as to what is causing the issue. Edit: The main issue is that, handle card entered is never firing.

# func to add a card to the hand
func add_card(card : Card) -> void:
	add_child(card) # add the card as a child of the hand node
	cards_in_hand.push_back(card) # push the card into the back of the cards in hand array
	
	# connect both mouse signals
	card.mouse_entered.connect(handle_card_entered) 
	card.mouse_exited.connect(handle_card_exited)
	
	reposition_cards(0.0)

# func to remove the card from the hand. Returns the card removed
func remove_card(index : int) -> Card:
	var card : Card = cards_in_hand[index] # get the card from the hand
	if card != null:
		# disconnect the mouse signals
		card.mouse_entered.disconnect(handle_card_entered)
		card.mouse_exited.disconnect(handle_card_exited)
		cards_in_hand.remove_at(index) # remove card from array
		remove_child(card) # remove card as child
	else:
		push_warning(str(index) + " is not a valid index")
		return null
	
	reposition_cards(0.0)
	return card

# func to handle the card entered. Pushes the card back in the touched cards array
func handle_card_entered(card : Card) -> void:
	print("enter") # test print
	touched_cards.push_back(card)
	
# func to handle the card exited. removes the card from the touched cards array
func handle_card_exited(card : Card) -> void:
	print("exit") # test print
	if touched_cards.size() == 0:
		push_warning("Tried to remove " + str(card) + " from touched cards")
		return
	touched_cards.remove_at(touched_cards.find(card))

Here are the two signal emittions if that is helpful, these come from the card script. I have an area2d in my scene and I connected it’s mouse enter and exit to these funcs

signal mouse_entered(card : Card)
signal mouse_exited(card : Card)

func _on_mouse_entered() -> void:
	mouse_entered.emit(self)

func _on_mouse_exited() -> void:
	mouse_exited.emit(self)

Testing these funcs in the card scene does work, I’ve tried a lot of things to get this to work, so now I’m at a loss. If you need anymore info please ask :D.

Hmm, looks fine to me. :thinking:

Edit: Can you add a print or breakpoint to your _on_mouse_entered function to make sure that it actually gets called when you run your game properly?

Can you share your scene tree? maybe you have a Control node blocking mouse events

When I run the card scene itself, it hits the breakpoint, but running it in the main scene does nothing. I was wondering if I am connecting the signals correctly but it looks good to me.

Looking at my scene tree I did have my mouse events stopped by my control nodes, but changing them to ignore doesnt change anthing ;-;

Check your debugger panel, the “Misc” tab shows which UI node is being clicked on

2 Likes

Thank you, this let me find out what was happening. My game screen is in a control node and it itself was blocking the mouse events. Thank you both for the help.