parent calling child node variable?

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

Hi,

I would like to understand how parent can call a variable from a child.
the tree is like that

map
>navigation
>some other nodes…
>unit
>mob
If i write in navigation node
var damage = 5
I can call it in mob node like this
health -= get_parent().damage

i would like to call var atak = 5 wich is in unit node,
and doing Something like this ( in navigation node) var damage = $unit.atak
I know that won’t work because the var damage don’t become the var atak from node unit.
I tried to link atak directly to the script on mob but it didn’t work too. And i don’t want it.

thx.

edit : finally if there is way to call variable child to child, i will take it.
i know i need to put onready before var damage = $unit.atak
But it Don’t work too.

KKIILLOOUU | 2020-06-02 02:42

:bust_in_silhouette: Reply From: drorya

you can reach it by it’s index:
self.get_child(1).atak

  • 1 is the Unit index- you count from up to down.:
    the first child’s index is 0 (navigation)
    the second is 1 (Unit)
    and the third is 2. (mob)
    and so on…

Hope it helps :slight_smile:

It works. Nice!
Thx

KKIILLOOUU | 2020-06-02 11:06