Passing Variables Around

Godot Version

Replace this line with your Godot version

Question

These are Multiple Questions that im Curios about
How do i send Information Up the Tree. Down a Tree and Sideways.
Example:
Parent → Child
Child → Parent
Parent → Parent

For a Easy Example lets say we are passing:
var Number: float = 1
If you want to Give Other Examples Thats good to keep it Simple!

i will Edit this Post to Include my Fav Answers.
Using GDScript.

Passing Down a Stack

extends Node3D #This is Parent

@onready var child = $Child
var number: int = 1


func _ready() -> void:
	child.ReceiveNumber(number)

extends Node3D #This is Child

func ReceiveNumber(_number):
	print("I GOT NUMBER! ", number)

Passing in any “direction” is the same. You need to have a valid relative path to the target node which gets you a reference to that node.

Checkout best practices from the docs.

I dont like having children being dependent on a parent so if the parent cares about some activity from the child the child provides a signal on an event or the parent has a reference to the child to check.

For sideways i like to use export variables. But this usually leads to boiler plate to handle scenarios where the export is not set and the node cant function without it. Through error or hard assert kind of thing.