r/godot•
tazerrtot

Is there a way to access a nodes properties using a NodePath?

help me

So basically I want to be able to set a value to a property that I identified using a NodePath- I'm basically trying to avoid a bunch of nested if/else statements.
For example, lets say I wanted to access a nodes global_position.x property using three strings put together, and I want to increase it by a float- basically something like this:

var a := "global_"
var b := "position"
var c := ":x"

var path: NodePath = a + b + c
get_property(path) += 1.0

Basically I have an exported resource with a bunch of exported enums with keys that coincide with strings inside dictionaries so that I can access them from the inspector- so I can define a property without extending the script and hopefully without a bunch of nested if statements. I know some nodes like Tween or AnimationPlayer have methods that access properties via NodePath, is there anyway to do this from a script?

Posted May 5, 2025, 1:59 AM UTC

115
Loading comments…