+1 vote

how do I get a value from a node path?
for example: @grp_Player:position:x
grp_Player is a KinematicBody2d by the way.

is there a function for this?
for example if my grp_Player's position is equal toVector(40,32),
I need a function that does something like this:

please don't answer as get_node(@"grp_Player").position.x for I need the get the value only from the nodepath itself.

in Engine by (191 points)
edited by

1 Answer

+1 vote
Best answer

You could split the path using the colon as separator and look up through the objects properties.

var path = "grp_Player:position:x"

var properties = path.split(":")

var obj = get_node(properties[0])
for i in range(1, len(properties)):
    obj = obj[properties[i]]

by (120 points)
selected by

oooooo I didn't I could access my object's properties like an array!
Thank you so much!

You could also use Object#get_indexed for the properties.

var properties = path.split(":", true, 1)
var obj = get_node(properties[0])
if properties[1]:
  obj = obj.get_indexed(properties[1])
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.