You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Setting transform for a Node2D outside the tree doesn't invalidate global_transform, so after setting transform, reading global_transform doesn't reflect the change.
Because set_global_transform internally sets transform and does not invalidate the global one, this also means that if you set global_transform and then immediately read it back, you don't get the transform you just set. This was why I noticed the bug.
I infer from #67710 that reading the global_transform of a Node2D which is outside the tree is expected to work and should return the transform relative to the root of the disconnected tree branch.
It seems that prior to 0a9f72d, a newly created CanvasItem's global_transform was marked as invalid, so the first time it is read, it is updated from the current transform. After that commit, the global_transform appears to be marked as valid from birth.
Manually invoking _invalidate_global_transform on the node causes global_transform to update as expected, the next time it is read. Perhaps the solution is doing that automatically in set_transform, something which currently only happens if the transform is in the tree?
Godot version
v4.1.stable.official
System information
Godot v4.1.stable - Arch Linux #1 SMP PREEMPT_DYNAMIC Wed, 21 Jun 2023 20:46:20 +0000 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3070 (nvidia; 535.54.03) - AMD Ryzen 9 5950X 16-Core Processor (32 Threads)
Issue description
Setting
transform
for aNode2D
outside the tree doesn't invalidateglobal_transform
, so after settingtransform
, readingglobal_transform
doesn't reflect the change.Because
set_global_transform
internally setstransform
and does not invalidate the global one, this also means that if you setglobal_transform
and then immediately read it back, you don't get the transform you just set. This was why I noticed the bug.I infer from #67710 that reading the global_transform of a Node2D which is outside the tree is expected to work and should return the transform relative to the root of the disconnected tree branch.
It seems that prior to 0a9f72d, a newly created CanvasItem's
global_transform
was marked as invalid, so the first time it is read, it is updated from the currenttransform
. After that commit, theglobal_transform
appears to be marked as valid from birth.Manually invoking
_invalidate_global_transform
on the node causesglobal_transform
to update as expected, the next time it is read. Perhaps the solution is doing that automatically inset_transform
, something which currently only happens if the transform is in the tree?A Node3D has the same behaviour, but it is still considered an error to access the global_transform outside the tree, and an error is reported when you try to do so.
Steps to reproduce
Make any node and attach a script to it:
In 4.1, the first assertion will fail. In versions before 0a9f72d, the first assertion will pass, but the second assertion will fail.
Minimal reproduction project
node2d-transform-bug.zip
The text was updated successfully, but these errors were encountered: