Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
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()
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.)