#(Godot 4) How do I get a parent node to listen to his instanced children scene's signals?

2 messages · Page 1 of 1 (latest)

lethal skiff
#

Hey there! I'm a newbie dabbling both in Godot 4 and programming for the first time, and after several hours of searching for this on my own, I have failed to do find a solution:

So I have this main Game scene, where one of its children, "ObstacleSpawner", spawns instances of "ObstacleLine" as his own children.
These "ObstacleLine" children spawn, then move to the left, and finally emit a signal once they get out of screen.

BUT I can't for the life of me figure out how to make the parent scene, ObstacleSpawner, listen to any and all signals emitted by his children scenes, which are spawned on runtime.

The idea is for them to emit a signal as they despawn, telling the ObstacleSpawner to trigger "spawn()" once again.

Any and all pointers would be much appreciated 🙏

vestal whale
#

when you spawn using instantiate() and then add_child() that object, then is the time to connect to the signal

it can be the obstacle spawner's job to return an obstacle back to the game

obstacle spawner

func spawn():
  var new_obstacle = ObstacleScene.instantiate()
  return new_obstacle

game

func _ready():
  do_new_spawn()

func do_new_spawn():
  var new_obstacle = obstacle_spawner.spawn()
  new_obstacle.obstacle_line_despawned.connect(_on_obstacle_line_despawned)

func _on_obstacle_line_despawned():
  do_new_spawn()