How can i get a variable from a Child Node?

Godot Version

Godot 4.1.3.stable


I don’t know how to get a variable from a child node and I can’t seem to find any posts about this issue.

Node2D # 2D Scene
-CharacterBody2D # Player
-Other stuff # Tilesets and such

im trying to get a variable not a thing like x.position

here’s my code in Node2D:

@onready var playernode = get_node("CharacterBody2D").health

I don’t know how to get it working

You are doing it right. But is health an actual variable on the node?

This would be more accurate to what this code is doing.
@onready var playerhealth = get_node(“CharacterBody2D”).health