+2 votes

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

Godot version 3.5
in Engine by (36 points)

2 Answers

0 votes

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.

by (19,194 points)
edited by
0 votes

Veya ┼ču kodu kullanabilirsiniz:

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

This should be working.

by (95 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.