why does an object that appears in the correct place in the editor teleport to origin on game start

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

I have an area 2d with a sprite child, collision polygon child, and animation player child. When I add this object to my game via the editor at, e.g., x = 30 and y = 70, it appears there in the editor, but when I run the game, it sets its position to 0,0.

Is the Area2D the root of the scene? Or is it a child of another node? Is there code defining what these nodes do? Is the position of the node the global position, or the relative position?

Ertain | 2023-01-29 03:30

:bust_in_silhouette: Reply From: samjmiller

Double check the code; if you have a script attached to the scene it may contain code that re-sets the object’s location at runtime…

For example in the script attached to my opening level, the _ready() function contains this line:

func _ready():
	player.position = Vector2(0,0)

Which will move the player from wherever I’ve positioned them on the map, and set them to the center of the scene. Maybe there’s something that is changing the position, or reparenting it to something with a different location?