0 votes

What is the difference between:
$Node.position = Vector(a,b)
$Node.set_position(a,b)

asked Jun 15 in Engine by igbow (24 points)

Both do the same don't worry about it.
I like using Node.position but that is just a preference.

1 Answer

+1 vote

Note: your use of set_position() is incorrect - it takes a single argument of a Vector2, not two arguments.

Using the position property is preferred. Properties will be suggested by autocomplete. set_ and get_ functions were used in Godot pre-3.0 - and still exist for compatibility - but they just make your code more verbose. Compare:

$Node2D.set_position($Node2D.get_position() + Vector2(100, 0))

versus

$Node2D.position += Vector2(100, 0)
answered Jun 15 by kidscancode (10,214 points)
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.