how to get property of other node without get_parent?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By vania23

Is it possible to get a property (like var damage) from other node without get_parent and so on? like do func on_collision(body): body.get(property) or something like that. Thank you

:bust_in_silhouette: Reply From: jgodfrey

To get the property of a node, you just need a valid reference to that node. It doesn’t matter how you get that reference as long as it’s valid. There are lots of ways to get a node reference, including get_parent(), direct scene tree navigation, via an in-built callback, signals, a singleton reference, …

With a valid node reference, you can reference the node’s properties directly.

:bust_in_silhouette: Reply From: Gangster53 YT

Veya şu kodu kullanabilirsiniz:

func _on_collision(body):
   var sample = body.your_variable
   ... (your_code) ...

This should be working.