This will probably be a very simple explanation but I've spent the last 20 minutes running tests, reading the docs and every other info I've found online and I'm more confused at every step. What the docs and all the resources I've found say, is that global_position is the absolute position of a node related to the world origin, while position is relative to the immediate parent's coordinates.

I have this setup:

Root node (Node3D)
|- Great-grand-parent node (CharacterBody3D)
|-- Grand-parent node (Custom node inheriting from Node)
|--- Parent node (Custom node inheriting from Node)
|---- Child node (Marker3D)

The child node has an offset of (0, -0.25, -0.5) that I've set in its transform in the editor.
No other nodes have any offset, that is: The great-grand-parent, grand-parent and parent nodes all share the same origin and move together and I'm doing nothing anywhere to move one of them separately from the others. I only move the great-grand-parent node.
So I'm moving the Great-grand-parent node around the scene and printing the global_position and the position properties of the child node and I'm getting that they're both the same: (0, -0.25, -0.5) no matter what I do. I would expect that global_position would be returning the great-grand-parents coordinates + (0, -0.25, -0.5).

Why is global_position not returning the coordinates to the world origin?

  • Toxe replied to this.
  • correojon It's because you have a Node in your hierarchy and they don't have a transform. Change your parent and grand-parent nodes to inherit from Node2D and that should fix your problem.

    correojon It's because you have a Node in your hierarchy and they don't have a transform. Change your parent and grand-parent nodes to inherit from Node2D and that should fix your problem.

      Toxe That makes so much sense, the transform inheritance chain was broken because the intermediate nodes had no transform at all. Thanks a lot Toxe!!