-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix invalid 2D global position when read outside tree #75509
Conversation
The global transform can still be not invalidated when changing top level for a CanvasItem outside the tree (it would need to be invalidated for the whole branch): godot/scene/main/canvas_item.cpp Lines 392 to 408 in 44d5394
|
@kleonc Does it lead to any issue? I tried bugging it, but it prints a correct global position. |
Here's an example: func foo() -> void:
var a := Node2D.new()
a.position = Vector2(1, 1)
var b := Node2D.new()
b.position = Vector2(2, 2)
a.add_child(b)
# b.global_position
b.top_level = true
print(b.global_position) With the |
2c9caf0
to
df5d509
Compare
Ok fixed. |
df5d509
to
727a4ed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
(haven't actually tested it after the changes though 🙃)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also looks fine to me.
Thanks! |
Cherry-picked for 4.0.3. |
MRP for the bug:
repro.tscn.txt
When you get
global_position
of a CanvasItem outside tree, it will assign its position to global position (roughly speaking). When the node enters tree, its global transform is not invalidated, soglobal_position
will still return its position. This also leads to some abnormalities, like sprite not displaying at its real position (as observed in the MRP).Bugsquad edit: Fixes #75676. Fixes #76327.