Cannot convert argument 1 from Object to Object

Godot Version

4.6.stable.official

Question

I’m seeing a bunch of these errors int he debugger when the game runs

E 0:00:13:627   emit_signalp: Error calling from signal 'gui_input' to callable: 'Control(Action.gd)::_on_gui_input': Cannot convert argument 1 from Object to Object.
  <C++ Source>  core/object/object.cpp:1406 @ emit_signalp()

which I THINK are triggered by this piece of code:

func _on_gui_input(event: InputEventMouseButton) -> void:
    if event.button_index == MOUSE_BUTTON_LEFT and event.is_action_released("click"):
        do_something()

But I have no idea how to debug it and the app seems to run normally when I left-click on that Control

The source triggering it seems to be this:

It’s just annoying because it’s flooding the output with those messages and it makes it tricky see the actual output I’m after.

You changed the function signature to InputEventMouseButton, but the signal emits InputEvent. Godot cannot up-cast every event to a mouse button.

3 Likes

Do this instead:

func _on_button_gui_input(event: InputEvent) -> void:
	var iemb: InputEventMouseButton = event as InputEventMouseButton
	if iemb:
		prints("actual mouse button event", iemb.button_index)
2 Likes

oh yep!

I need to go the whole route, don’t I


func _on_gui_input(event: InputEvent) -> void:
    if event is InputEventMouseButton:
        var mouseEvent:InputEventMouseButton = event as InputEventMouseButton
        if mouseEvent.button_index == MOUSE_BUTTON_LEFT and mouseEvent.is_action_released("click"):

jinx :slight_smile:

It’s not necessary to check if a type conversion is possible using is before making the actual conversion with as. If the type conversion is not possible, as operator result is null.