How get node in other scene tree

Godot Version

4.3

Question

example: there is some scene:

  • world: the main scene of game. it include player scene and enemy scene
  • player: has it’s some info, such as health, whatever.
  • enemy: want to know player health

In the enemy ready function, how to get player’s hp?
I have watch a tutorial video. His solution was put player in a group. then enemy @onready var player = get_tree().get_first_node_in_group('player') as Player
I’m wondering if there’s any other way

Yeah there are several ways to do this, like:

@onready var player := get_node('/root/world/player')

The world is the name of the main scene, and player is the name of player. You need to change it if it is not same.

1 Like

this way is very depend node path, but In some situations,it’s good way too. thank you

1 Like

oh, official document,already give the solution Alternatives

1 Like

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