How to make signals communicate across scenes?

Godot Version

godot 4

Question

How to make signals communicate across scenes?
I have these two nodes, the player, and THEROCK (a random rock you can interact with). I had a bunch of signals between them, but then i remembered that people say its better to save each node as its own scene. But when i did that now I don’t have the option to connect signals between them.

connect the signal after you instantiate the scene.

extends Node2D

var v_button_scene = preload("res://Signal/SignalBetweenScene/ButtonScene.tscn")

func _ready() -> void:
	var v_button_scene_root_node = v_button_scene.instantiate()
	v_button_scene_root_node.get_node("MyButton").pressed.connect(Callable(func(): print("Clicked")))
	add_child(v_button_scene_root_node)

Untitled

this is the ButtonScene.tscn contents

Thank you, but I’m really new to this so can you explain what all of this means and how i would adapt it to my situation?
These are my nodes:
Per (characterbody2d)

  • CollisionShape2D
  • AnimatedSprite2D
  • Camera2D
    THEROCK (staticbody2d)
  • InteractComp (area2d)
    • CollisionShape2D
    • Sprite2D
  • CollisionShape2D

And these are the signals I need:

Characterbody2D (named “Per”):
* interacted()

Area2D (named “InteractComp”)
* body_entered()
* body_exited()
I need interacted() to connect to connect to the interactcomp node and body_entered and body_exited to connect to the Characterbody2d node (Per)

What’s the main scene above this? My platform game has scenes such as “level 2” which then contain other scenes such as “player” and “coins”

I then use code like that:

func _on_body_entered(body):
	if body.name == ("player"):
		print("COIN")
		global.score += 10
		global.coins += 1
		print (global.score)
		print (global.coins)
		$AnimatedSprite2D.visible = false
		$CollisionShape2D.set_deferred("disabled",true)
		end_level()

I know that’s not a 100% answer to your question, but I’m happy to chat and help. :smile:

I’ve been learning Godot over the last month, and have built a few cute items. You can check out my YouTube channel and/or my itch.io for examples of my work.

Thanks for helping, I actually ended up fixing everything by right clicking each node in the main scene and clicking “editable children”

Thanks for helping, I actually ended up fixing everything by right clicking each node in the main scene and clicking “editable children”

1 Like

Nice. I’ve never used that so I’ll have a look at it.