#Is it bad practice to define my player directly and modify it from another sibling node?

1 messages · Page 1 of 1 (latest)

mild ice
#

yeah, in my opinion it's bad practice to use an absolute path (it will break if you rename the scene or the player) and not needed at all. You can put your player into a group and check that

# area2d.gd
func _on_body_entered(body: Node2D) -> void:
    if body.is_in_group("player"):
        body.health = 0

Or you give your player a class_name

# player.gd
class_name Player
# area2d.gd
func _on_body_entered(body: Node2D) -> void:
    if body is Player:
        body.health = 0
reef beacon
#

I'd also add that changing a field of another class is not best practice. It's better to call a method so the called class can decide how to update its own state.