0 votes

i have seen some solution regarding this. But those solution are not working maybe due to they are for older godot versions.
I want to get and set properties of a node using GDScript. Properties in Inspector like get and set texture, get and set position, get and set size of node, etc.

Is there a common function which we can call in GDScript to get and set properties of a node easily ?

in Engine by (44 points)

1 Answer

+3 votes
Best answer

You can get and set any property of a node using its name. You can see its name when you hover over the property in the Inspector, or you can look at the API reference for that node, which has a list of its properties.

For example, to get the "Position" property:

print(position)

and to set it:

position = Vector2(100, 100)

If you want to access a property on another node, use . notation:

$Sprite.texture = load("res://image.png")

I highly recommend reading the official tutorial, which shows much of this essential functionality:

https://docs.godotengine.org/en/stable/getting_started/step_by_step/index.html

by (20,485 points)
selected by
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.
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.