TecBrat
TecBrat

Reputation: 3729

Method not found when emitting a custom signal, but the game seems to work when played

In Godot 4.1.1 I moved some scenes and started getting parenting errors. I think I got that fixed, but I'm mentioning it in case it is important.

I have an Area2d called House. house.gd has two custom signals

signal player_entered
signal player_exited

func _on_body_entered(body):
    print("Emitting player_entered")
    player_entered.emit()

func _on_body_exited(body):
    print("Emitting player_exited")
    player_exited.emit()

The custom signals are connected to a scene called Outside.

In outside.gd I have

func _on_house_player_entered():
    print("Player Entered House!")
    var tween = get_tree().create_tween()
    tween.tween_property($Player/Camera2D,"zoom",Vector2(.5,.5),1)

func _on_house_player_exited():
    print("Player Exited House!")
    var tween = get_tree().create_tween()
    tween.tween_property($Player/Camera2D,"zoom",Vector2(.2,.2),1)

When I run the outside scene, I can enter the house and the camera zooms. I can exit the house and the camera zoom resets.

So far, so good.

The debugger gives two errors:

E 0:00:35:0663 house.gd:20 @ _on_body_entered(): Error calling from signal 'player_entered' to callable: 'Area2D(house.gd)::_on_player_entered': Method not found. <C++ Source> core/object/object.cpp:1082 @ emit_signalp() house.gd:20 @ _on_body_entered()

and

E 0:00:36:0414 house.gd:26 @ _on_body_exited(): Error calling from signal 'player_exited' to callable: 'Area2D(house.gd)::_on_player_exited': Method not found. <C++ Source> core/object/object.cpp:1082 @ emit_signalp() house.gd:26 @ _on_body_exited()

I removed the relevant code from both files, re-attached all four signals and pasted the code back in the files. I still get the errors. What am I doing wrong? (I'm only 7 hours into my first lesson, so there's a lot I don't know.)

Upvotes: 0

Views: 1000

Answers (1)

TecBrat
TecBrat

Reputation: 3729

My solution was to carefully disconnect every signal from every node involved, then re-implement and reconnect each signal. Now it works with no error. Because I don't know what goes on in the background, I don't know what the root cause was. I'd be happy to accept someone else's answer if they can explain it.

Upvotes: 1

Related Questions