• Godot HelpGUI
  • Input events on UI still being passed to game entities

My player object uses mouse clicks to move, the player essentially clicks a location in the world and the player object moves to that location. I've added a button to my game that the player can press but whenever the button is clicked, the player object still moves to that location. I have a feeling I'm missing something as most of the documentation says that the GUI should use the input event, and then not pass it on to other objects.Here's the code on the player object that listens for the event[code]func ready(): set_fixed_process(true) set_process_input(true)func input(event): if (event.type == InputEvent.MOUSE_BUTTON && !event.is_echo()): move_to_target(get_global_mouse_pos())[/code]and the code currently attached to the button itself[code]func _input_event(event): if (event.type == InputEvent.MOUSE_BUTTON && event.pressed): get_node("..").change_mode()[/code]What have I missed?

Does the move_to_target make use of a raycast? might you be able to implement a check in there for the raycast to see if its hitting a button first? (if so you should make it drop out of the move_to_target function, I think. this is off the top of my head though and your issue might be something else)

I didn't try it but this should help:[code]func _input_event(event): if (event.type == InputEvent.MOUSE_BUTTON && event.pressed): get_node("..").change_mode()                get_tree().set_input_as_handled()[/code]IIRC this should make sure that the event isn't handled by any other node/script after SceneTree.set_input_as_handled() was called

[quote author=Megalomaniak link=topic=15596.msg16668#msg16668 date=1465403782]Does the move_to_target make use of a raycast? might you be able to implement a check in there for the raycast to see if its hitting a button first? (if so you should make it drop out of the move_to_target function, I think. this is off the top of my head though and your issue might be something else)[/quote]I'm not implementing a raycast in move to target (for reference it's a top down 2D game), but I'll definitely look into that as a solution.[quote author=danjo link=topic=15596.msg16669#msg16669 date=1465404022]I didn't try it but this should help:[code]func input_event(event): if (event.type == InputEvent.MOUSE_BUTTON && event.pressed): get_node("..").change_mode()                get_tree().set_input_as_handled()[/code]IIRC this should make sure that the event isn't handled by any other node/script after SceneTree.set_input_as_handled() was called[/quote]Unfortunately this didn't work, which makes me believe that my player code might be getting a different event from the one that is passed to the button somehow.Mid reply update: I managed to get it working by instead using the unhandled_input(ev) function in my player code, rather than regular _input(ev).  I'm a little iffy on using this as a solution as I have no idea what it might break later on, but it seems to be working for my current problem. Thanks for your help guys.

6 years later