0 votes

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?

Godot version Godot 3.3
in Engine by (79 points)
edited by

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.

2 Answers

0 votes

When you see a colon in a path it means it's a NodePath not a dictionary key. https://docs.godotengine.org/en/stable/classes/class_nodepath.html

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.

by (3,710 points)

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

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

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.

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

0 votes

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
by (444 points)
edited by

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

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 webmaster@godotengine.org with your username.