-
-
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 global transform validity for Node2D
and Control
#80105
Conversation
8b92da3
to
7e9855e
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.
This is not a correct fix.
The global_invalid
flag being initialized to false is correct. A newly created CanvasItem has no parent and its own transform
is an identity, hence global_transform
being an identity by default is valid.
Marking global transform as invalid by default would result in some unnecessary one-time updates for actually unchanged global transforms. But it doesn't solve the issue which is: some out of tree modifications (like Node2D.set_global_position
) result in not marking the global transform as dirty.
E.g. with this PR:
@tool
extends EditorScript
func _run() -> void:
var a = Node2D.new()
a.global_position = Vector2(1, 1)
assert(a.global_position == Vector2(1, 1)) # Passes because of invalid by default.
a.global_position = Vector2(2, 2)
assert(a.global_position == Vector2(2, 2)) # Still fails.
Also I'm not sure if the global_invalid
to global_valid
name change is needed/wanted at all.
7e9855e
to
1ab469d
Compare
@kleonc Thank you for pointing me in the right direction. I have included your improvements in the PR. |
1ab469d
to
3c80e66
Compare
@Sauermann There's also |
3c80e66
to
53c5251
Compare
Node2D
and Control
I have included the invalidation for transform-changing operations in |
@kleonc may I ask if your requested changes have been resolved by my updates? |
Hmm, seems like it should now be properly invalidating the global transforms. 👍 However, I'm not sure if these added invalidations don't affect transform notifications in some unwanted manner. Specifically, after brief look at the code, when in the tree godot/scene/main/canvas_item.h Lines 154 to 162 in 16a9356
which early returns in case global transform is invalid: godot/scene/main/canvas_item.cpp Lines 877 to 886 in 16a9356
Hence I wonder if adding |
53c5251
to
968d71b
Compare
Thank you for taking the time to guide me through the maze of Transform-caching. With the latest updated I made sure that
|
968d71b
to
4dd2a16
Compare
Set global transform to invalid when changing transform
4dd2a16
to
152572a
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.
Tested locally (rebased on top of master
6758a7f), it works as expected.
I've also tested a few demo projects (3D Platformer, Control Gallery) and they behave correctly.
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.
AFAICT it should work fine now. 👍
Thanks! |
Cherry-picked for 4.1.2. |
Set global transform to invalid when changing transform
resolve #79453
Add unit-tests for the bug