Godot: Global Position is ignored when using set_as_toplevel

Created on 27 Oct 2020  路  5Comments  路  Source: godotengine/godot

Godot version:

Tested on: 3.1.1 stable, 3.2.2 stable, 3.2.3. stable and 3.2.4 beta 1

OS/device including version:

W10 64 bit

Issue description:

When testing #43121 I found out that Global Position of children doesn't seem to be accurate when set_as_toplevel is true, which resulted in a wierd jump between 2 points when switching set_as_toplevel on and off. Printing the Global Position demonstrated that the Global Position Didn't change, meaning the "Global Position" is ignored when set_as_toplevel is set to true and instead uses only the node's relative position to the parent as it's actual position.

Steps to reproduce:
Make a Scene
Make a Child node to the root and place it at coords different from the root
To that Child add a Runtime Visible Node (like a Sprite)
Attach a Script to the Sprite that prints Global Position, and can toggle set_as_toplevel
Observe Jumping between 2 points as toggled, while Global Position Doesn't change

Minimal reproduction project:

Global Pos.zip

bug core

Most helpful comment

Ah my bad, I think I misunderstood the issue. You are right, the problem is in the global_position not updating properly. This is annoying...

All 5 comments

This is an expected behavior. You seem to expect that the global_position position will keep its value, while in fact it's the position property that does. Since global_position is simply a proxy property for the underlying position one, it is normal that "position" keeps its value while "global_position" is modified depending on the toplevel status.

Closing as this is an expected behavior.

Ah my bad, I think I misunderstood the issue. You are right, the problem is in the global_position not updating properly. This is annoying...

I made a PR, if you want to give it a try: #43131
Seems like it solve the problem.

Sadly unable to test for 2 reasons:

  1. Master Branch currently has an issue that prevents me from running Scenes, thus making it impossible to test due to issue #41599 and/or issue #42251
  2. Unable to build in general atm, due to not having the tools, nor the knowledge to use them, which is fixable but sadly don't have enough time (especially in a nice chunk) to devote to setting that all up yet and learning to use all that.

Ok, no problem. It solve the issue for me so I guess it's enough.
It should likely be cherry-picked so you will probably be able to test it in the next 3.x release.

Was this page helpful?
0 / 5 - 0 ratings