How to fix the "method expected 0 arguments but called with non-zero" error?

Godot Version

v4.6.1.stable.official [14d19694e]

Question

So I have an interactable area scene, which basically shows a label when entered and hides it when exited. Seems simple enough, so I tried to connect the entered/exited signals to the label’s show/hide functions directly. However, when I try to actually interact with the area, it shows this error:

E 0:00:10:940 emit_signalp: Error calling from signal ‘area_entered’ to callable: ‘HBoxContainer::show’: Method expected 0 argument(s), but called with 1.
<C++ Source> core/object/object.cpp:1406 @ emit_signalp()

So now I have two extra functions with an unused argument, each containing one line for actually showing the damn label.

func show_label(_area: Area2D = null) -> void:
	$InteractLabel.show()

func hide_label(_area: Area2D = null) -> void:
	$InteractLabel.hide()

Seems kinda redundant. Any way to do it better?

If you know that only one character can get the label to show, you can just reverse the visibility.

$InteractLabel.visibile = !$InteractLabel.visible

You can add and remove arguments from signals in the menu where you connect them to functions. There is a separate button for “advanced settings”, “argument settings” or something like that. You can remove the area-argument there but it shouldn’t make any difference. It looks like your problem now is that you call it with 1 argument from elsewhere in your code, when it expects zero. Or does the problem occur when walking into the area? Have you tried calling it by some input, just to see if it works?

I guess you could also just remove the argument part from within the brackets?

Forget what I said! I just checked and you can’t remove arguments in that menu. It’s only possible to add arguments.

But i wonder why you would want to remove it anyway. Would you for example want a bullet or enemy with an area to toggle the menu on/off? The reason you have an area argument there is to check if you want the function to run. Like if area.is_in_group(“player”): run the rest of the function, or something like that.

unfortunately I don’t know any way to work around this limitation currently.

You can add argument (with the bind() function in code, and with the connect UI in the editor) but you cannot remove them.

Well, yeah, but there are also collision layers, and I currently have a dedicated player-interact layer, exclusively for NPC/object interactions. So I figured if nothing else is ever on that layer, the area argument isn’t particularly necessary. Is that a bad idea?

You can, with Callable::unbind(), and that’s exactly what @snowystoat should be doing.
Something like that:

func _ready() -> void:
	area_entered.connect($InteractLabel.show.unbind(1))
1 Like

No it’s not a bad idea! It is how you are supposed to use layers! I just don’t use them myself and it slipped my mind that the feature exists! I find that it is easier to quickly remember what code does if I can see instantly that OK this is only meant to happen when players / enemies / whatever enters.

Anyway, i don’t really understand why you get the error message. It says that you call the function with 1 but the function expects 0. But when looking at the call it has 0 arguments. It’s kind of weird i.m.o. Or i assume that the error message is for the line $InteractLabel.show(), not from a call elsewhere in the script?

HOLY HELL IT WORKS. I just read a bit on the unbind func and I guess didn’t quite understand what it means, I interpreted it as unbinding an argument off a function instead of the signal, and given that the show/hide funcs already have 0 arguments, I assumed it wouldn’t work. Thanks for making me double-check.

1 Like

Well TIL you can unbind arguments thanks to you!

Thanks for pointing it out

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.