Godot 4.2
I’m trying to create a highlighted-while-hovering mode for my card game, but I’m having trouble receiving mouse input on control nodes. Suppose I have a scene with nothing but a ColorRect with the following script:
`func _on_mouse_entered():
self.color = Color.BLUE
func _on_mouse_exited():
self.color = Color.YELLOW`
I’m hovering over this rect and it’s not turning yellow. Signals are connected and mouse filter mode is set to stop. Not sure what I’m doing wrong, any ideas?
Thx for reading, hope you can help!
With that exact code, it will only turn yellow once the mouse has entered then exited the rectangle’s visible area.
If you click on your card, and look at the Misc tab in the Debugger panel, you can see which Control has received the input. maybe another Control is blocking the input.
4 Likes
Thanks for the responses guys. Here’s a little clarification.
The rectangle won’t even turn blue when I hover over it. There’s no other control node to eat up the signal in this scene as it’s all alone. Provided some pics.
pic is of the script exactly how it is
Debugger > Misc showing clicked control is the ColorRect
Pic of game output
I’m really stumped on this one, friends.
Aloa thomasparas,
as always when using graphical interfaces: we cant really follow what you did in your editor, especially where you registered the signals from.
Another hint, just put code in code blocks, so people can copy it.
I have the following minimal example in gdscript:
extends ColorRect
var width:int
var height:int
func _ready() -> void:
width = ProjectSettings.get_setting("display/window/size/viewport_width") / 2
height = ProjectSettings.get_setting("display/window/size/viewport_height") / 2
position = Vector2(3*width/4, 3*height/4)
size = Vector2(width/2, height/2)
self.mouse_entered.connect(_turn_blue)
self.mouse_exited.connect(_turn_yellow)
func _process(delta:float) -> void:
pass
func _turn_blue() -> void:
self.color = Color.BLUE
func _turn_yellow() -> void:
self.color = Color.YELLOW
Attached to a ColorRect as the scene and it works as expected:

Edit: If the animation of the gif ended just open it in a new browser tab.
I can only assume you did something wrong with registration of the signal in the editor.
Kind regards,
KowalewskajA
1 Like
Hello KowalewskajA
I appreciate the tips and response! It’s my first time here asking for help so still learning the ropes. Thanks again for taking the time to write out the above and record an example.
So I tried using your script in a new ColorRect within my cardgame project and it didn’t work. Then I created a brand new project from scratch, and it works! Could there have been something I’ve done with the project settings that could cause this behavior?
Aloa thomasparas,
obviously it can be (as you experienced), but tbh that is something that more experienced people with the engine have to answer.
If you figure out what or how you changed it feel free to let us know, as this is learning that we all can benefit from.
I personally realised that I like to do nearly everything with gdscript (as far as I learned) because than I can just setup a new project and test stuff there and know I did not change something. But I am glad you have now a version that is working as you expect it.
Kind regards,
KowalewskajA
1 Like
I wanted my ColorRect to receive mouse_entered and mouse_exited signals but they never triggered. I found my mistake and want to share it here, because people will often look up this title and its a common mistake:
The tree order of control nodes matters when receiving signals: My ColorRect was at the top of the tree and some other lower placed VBoxContainer (mouse_filter was on Stop) stopped the signal before it could reach the ColorRect
Here is the documentation: https://docs.godotengine.org/en/stable/tutorials/inputs/inputevent.html
3 Likes