`This is for a 3D game. Under the main Node3D I have a child Camera3D node to which I have attached a script. In that script I created a Tween. The Tween animation is written in _ready() of the child node script. I want to connect the finished signal of the Tween to the main Node3D script but I get this error
"E 0:00:01:0029 main.gd:95 @ _ready(): In Object of type ‘Camera3D’: Attempt to connect nonexistent signal ‘finished’ to callable ‘Node3D(main.gd)::_on_player_view_camera_loading_camera_animation_done’.
<C++ Error> Condition “!signal_is_valid” is true. Returning: ERR_INVALID_PARAMETER
<C++ Source> core/object/object.cpp:1344 @ connect()
main.gd:95 @ _ready()
" `
Actually, I’m able to get the desired behavior when I comment lines 95, and 9. Then uncomment line 10.
In line 10, I’m able to use finished signal to call xxx_animation_done() in parent node. But I think this isn’t the right way to do it.
Following Observer pattern, I want the Camera3D node to just emit the signal and not care about who uses it. That is, I want to do the signal to function binding at the destination, which here is the parent node script.
I’m not able to do it. Line 95 always throws the error that the signal doesn’t exist.
If you could tell me how to do it in the parent script, that would be great!
When it gets the signal it will connect to whatever callable you have put in there, in this case ‘_on_my_long_method_name’
So when your camera gets the signal finished, it emits the custom signal loadingCameraAnimationDone. You main script is now connected to that signal and calls its own method func _on_my_long_method_name()
Your signal I would call camera_ready, not loadingCameraAnimationDone. Then you connected method could be simply _on_camera_ready() which is a lot more readable. Personal preference I suppose.
Best wishes,
Paul
PS if you use this:
@onready var Camera = $PlayerViewCamera
Then you calls are even more readable.
# Better signal name
signal camera_ready
func _on_tween_finished():
camera_ready.emit()
# Better variable names
Camera.camera_ready.connect(_on_camera_ready)