Signal between Roots

Godot Version

Godot 4.2.2 Stable

Question

I made two “Roots”, one for the player and another for a pathway, and I want the pathway one to emit a signal to the player whenever the player steps on a pathway, but thing is that it just doesn’t let me connect the signal from the pathway to the player both through the signal list and by script.

image
image

You could connect them together in your “main”/“world” scene where both player and pathway are instantiated.

Though if you need dynamic connections you need to get the pathway dynamically too. I do not know how you intend to set these up or what they do, but groups are pretty good way to find objects.

Add your pathways to a group for example “Pathway” then the player can use get_nodes_in_group("Pathway") to connect to each one

extends CharacterBody2D

func _ready() -> void:
    var pathways: Array[Node] = get_tree().get_nodes_in_group("Pathway")
    for pathway in pathways:
        pathway.player_entered.connect(_on_player_entered_pathway)

func _on_player_entered_pathway() -> void:
    print("entered a pathway")
1 Like

It worked just fine!!

Found a few errors on my end but at least now I can link the signals that way, the rest is up to testing it out, Ty!!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.