Dynamically change built-in properties for a node

Godot Version

4.5.1.stable

Question

I’m trying to make a function that dynamically changes the properties of a node (e.g: x position, y scale, variables, etc).

I understand that you can use .get() and .set() to dynamically get / set variables in a node, however, is there an alternative for built-in properties (scale, position, visibility, etc)?

Thanks!

You can use get and set for built in properties as well.

If you are working typing variables, like var some_node : Node3d instead of var something, when editing the script and type some_node and dot, the list of properties and methods will be displayed.
For creating your own getters and setters, you can expose a variable name and through the setter and getter set and get the values too. This way, you can add logic or validations.
Example:

var _input_dir : Vector2 = Vector2.ZERO
var _jump : bool = false
var _crouch : bool = false
var _run : bool = false
var _interact : bool = false

var input_dir : Vector2 :
get():
return _input_dir

var jump : bool :
get():
return _jump

var crouch : bool :
get():
return _crouch

var run : bool :
get():
return _run

var interact : bool :
get():
return _interact

add get in from of the property to use the method:


global_position #**property**
get_global_position() #**method** of the property, returns Vector2
set_global_position(Vector2(1, 0)) #**method** of the property, sets Vector2

you can find these in the documentation or by Ctrl+Clicking on the property.

every single property in the engine has a get and set methods.

What exactly do you mean by “dynamically change”? Do you mean “while the game is running”? If so, they’re properties, just change them with an assignment.

position.x = 1.0
scale.y = 0.5

Using getters and setters is just more verbose code.

If you’re asking how you do that - use a script. If you want a more specific answer, you’ll have to give a more concrete example.