Mistake with "body_entered" signal

Godot Version

<4.2.2>

Question

<godot spams mistake

E 0:00:25:0888   ladder_event_1.gd:16 @ _process(): Error calling from signal 'body_entered' to callable: 'Area2D(ladder_event_1.gd)::_on_body_entered': Method expected 1 arguments, but called with 0.
  <Исходный код C++>core/object/object.cpp:1140 @ emit_signalp()
  <Трассировка стека>ladder_event_1.gd:16 @ _process()

it works as intended but i wonder why it gives mistake
mistake happens with both “body_entered” and “body_exited” signals


the problem might be with body, what is the body variable? the error is saying that you are calling the function that requires a argument but you arent giving it a argument. the “body” variable should be the collision shape

the connected lambda needs to take an argument even if it doesn’t use one, or unbind 1.

ladder.body_entered.connect(func(_body):
    entered = true)
# or
var ladder_event = func():
    entered = true
ladder.body_entered.connect(ladder_event.unbind(1))

Make sure to paste code with formatting, between three ticks like so

```
type or paste code here
```

1 Like

amazingly, this generates another mistake

E 0:00:03:0744   ladder_event_1.gd:7 @ _on_body_entered(): Error calling from signal 'body_entered' to callable: 'Area2D(ladder_event_1.gd)::_on_body_entered': Method expected 1 arguments, but called with 0.
  <Исходный код C++>core/object/object.cpp:1140 @ emit_signalp()
  <Трассировка стека>ladder_event_1.gd:7 @ _on_body_entered()
E 0:00:01:0858   ladder_event_1.gd:7 @ _on_body_entered(): Error calling from signal 'body_entered' to callable: 'Node2D(inventory.gd)::ladder_event_1_entered': Method expected 1 arguments, but called with 0.
  <Исходный код C++>core/object/object.cpp:1140 @ emit_signalp()
  <Трассировка стека>ladder_event_1.gd:7 @ _on_body_entered()

Seems like the same error message, can you post the updated script?

i tried both and they don’t fix it :confused:
thanks for suggesting tho

Ah the real issue is you are emitting signals yourself, do not do this as body_entered and body_exited already emit when something enters, that’s how your “ladder_event_1.gd” script is working, notice the error points out “_on_body_entered called with zero arguments”? The engine is getting terribly confused because this signal is being handled with body in ladder_event.gd but emitted without body, in your inventory.gd you connect to the same erroneous signal.

I would remove this entire script, or you can change it to emit the signal you created rather than try to emit signals that already exist.

extends Area2D
signal entered_area

func _on_body_entered(body) -> void:
    if body.name == "ryuji":
        entered_area.emit()

thanks! guess this is only way around

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