Get dictionary value from another node using get()

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

When using tween, passing dictionary value path as "physical_property:rotation" works fine

But when I’m trying to pass this onto get(), instead they return null.

var val = object.get("physical_property:rotation")

This is a function that supposes to get value from another node.
What’s the right nodepath for dictionary value?

I can do a workaround with get("physical_property")["rotation"] but the thing is that the code and passing argument would get more complicated since some properties are not contained in dictionary and will need to pass more arguments than neccessary.

Multirious | 2021-07-05 08:15

:bust_in_silhouette: Reply From: timothybrentwood

When you see a colon in a path it means it’s a NodePath not a dictionary key. NodePath — Godot Engine (stable) documentation in English

get_node_and_resource() is close to getting what you want but I think you would either need to dynamically generate the NodePath at runtime or hard code it - which probably isn’t what you want.

I think you are doing the most straightforward method of getting what you want but I could just be naive of a function.

Haven’t tried this yet, but why is passing "physical_property:rotation" in Tween works? I thought Tween would using the same setget function.

Multirious | 2021-07-05 16:54

Because a Tween expects a NodePath as the second argument:
Tween — Godot Engine (stable) documentation in English

timothybrentwood | 2021-07-06 03:32

Yeah, tried using get_node_and_resource and it’s not working :confused: It does return the node and the remaining path but it does not return any property, it’s just null.

Multirious | 2021-07-06 10:24

It’s possible you’re not forming the NodePath right or something. I would just stick to using get("physical_property")["rotation"] like you were doing.

timothybrentwood | 2021-07-06 16:51

Yeah, I decided to do this and putting every single variable in a dictionary instead.

Multirious | 2021-07-07 06:34

:bust_in_silhouette: Reply From: vnmk8

you can also access another node’s values by referencing the node like:

var other_node = get_node("other_node")
var some_value = other_node.other_node_variable

The purpose of the function is to get every possible variable in a node. So, this method is not very flexible.

Multirious | 2021-07-06 05:26