Physics Interpolation 2D - fix light and light occluder resetting

It turns out `NOTIFICATION_TRANSFORM_CHANGED` is deferred for these nodes, which can mean the transform is not set in the `VisualServer` until after the reset has been sent, even if the transform is set before the reset in script. This prevented the reset from acting correctly.

Here we explicitly set the transform prior to each reset, to ensure the `VisualServer` is up to date.
This commit is contained in:
lawnjelly 2024-03-16 16:02:22 +00:00 committed by Relintai
parent 010b8ba73b
commit 942a304f4e
2 changed files with 12 additions and 2 deletions

View File

@ -320,7 +320,12 @@ void Light2D::_notification(int p_what) {
} break; } break;
case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: { case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: {
if (is_visible_in_tree() && is_physics_interpolated()) { if (is_visible_in_tree() && is_physics_interpolated()) {
RenderingServer::get_singleton()->canvas_light_reset_physics_interpolation(canvas_light); // Explicitly make sure the transform is up to date in VisualServer before
// resetting. This is necessary because NOTIFICATION_TRANSFORM_CHANGED
// is normally deferred, and a client change to transform will not always be sent
// before the reset, so we need to guarantee this.
RS::get_singleton()->canvas_light_set_transform(canvas_light, get_global_transform());
RS::get_singleton()->canvas_light_reset_physics_interpolation(canvas_light);
} }
} break; } break;
} }

View File

@ -203,7 +203,12 @@ void LightOccluder2D::_notification(int p_what) {
} break; } break;
case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: { case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: {
if (is_visible_in_tree() && is_physics_interpolated()) { if (is_visible_in_tree() && is_physics_interpolated()) {
RenderingServer::get_singleton()->canvas_light_occluder_reset_physics_interpolation(occluder); // Explicitly make sure the transform is up to date in VisualServer before
// resetting. This is necessary because NOTIFICATION_TRANSFORM_CHANGED
// is normally deferred, and a client change to transform will not always be sent
// before the reset, so we need to guarantee this.
RS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform());
RS::get_singleton()->canvas_light_occluder_reset_physics_interpolation(occluder);
} }
} break; } break;
} }