Godot Version
4.1
Question
Hello what’s the best way to trade info between two scenes? in my game I’m trying to make an object (that’s in another scene) that when hit by a raycast restores the players health or gives them ammo etc and updates a progress bar node. I’ve tried to use classes but i cant seem to get it to work.
Let the object scene emit a signal that player (or game logic script) can connect to.
You can use groups for that:
# On your player script:
func _ready() -> void:
add_to_group(“player“)
So from any node you can use get_tree().get_first_node_in_group(“player“) to get a reference to your player node. You can also direct call any function from your player script using get_tree().call_group(“player“, “function_name“, arg1, arg2, etc) so you can call a function that give ammo/health to the player.