Function get_pos() does not work

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By thiago

Hi, all

I have just started using Godot and I am having a hard time using the get_pos().
I tried on both KinematicBody2D and Node2D

I always get and error like this:

Nonexistent function ‘get_pos’ in base ‘Node2D (Node2D.gd)’.

I did a very simple script just to test and still getting the error.

extends Node2D

func _ready():
	print("POSITION: " + get_pos())

Any ideas on what I am doing wrong?

:bust_in_silhouette: Reply From: kidscancode

You’re looking at documentation or examples for Godot 2.1. In 3.0, names and functionality was changed. For examples, abbreviations like “pos” and “rot” were changed to “position” and “rotation”.

In addition, you no longer need to use get/set methods to access node properties. You can use the variables directly. Your example script would become:

extends Node2D

func _ready():
    print(position)

You can see the full list of a node’s properties in the docs. In addition, the editor’s autocomplete will suggest them. For example, here’s the Node2D list: Node2D — Godot Engine (3.0) documentation in English

Thanks!

The tutorial I watched must have been done in older version of the engine.

thiago | 2018-03-24 16:06

I was following the pong tutorial on documentation and faced the same issue.
Just swap get_pos with get_position and set_pos with set_position and you are good to go.
Thanks for the tip!

regis_souza | 2021-01-10 20:27