+1 vote

Hello everyone, i'm a godot novice and just started learning gdscript :)
There seems to be multiple ways to access an objects/class/nodes? name.

say i got a node and i wanted to get either a name or a custom property:


With custom properties it's just these two i know of:

health = 10;


What is the prefered method and why?

asked Apr 7, 2019 in Engine by threepwood (13 points)

1 Answer

+3 votes

node.health is the preferred syntax – built-in properties also use this syntax since Godot 3.0. However, get() and set() can be useful to get/set properties with dynamic names (that is, the property's name itself is variable).

There's one other case where you must use get()/set(): when a property name contains special characters such as / (which may be the case of a few built-in properties).

answered Apr 7, 2019 by Calinou (6,478 points)

Thanks :) Great answer!

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 How to use this Q&A? before posting your first questions.