From bcfca5ec8615cf796dcb02d4291d9475feb58031 Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Sat, 5 Aug 2023 08:33:19 +0100 Subject: [PATCH] Physics Interpolation 2D - reset on NOTIFICATION_ENTER_TREE As a convenience, physics interpolation is reset automatically on entering the tree. This will be desired in most situations, and saves the user having to write code for this explicitly. --- scene/2d/canvas_item.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 8539ce9093d..dc2febdc2f0 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -583,6 +583,19 @@ void CanvasItem::_notification(int p_what) { if (!block_transform_notify && !xform_change.in_list()) { get_tree()->xform_change_list.add(&xform_change); } + + // If using physics interpolation, reset for this node only, + // as a helper, as in most cases, users will want items reset when + // adding to the tree. + // In cases where they move immediately after adding, + // there will be little cost in having two resets as these are cheap, + // and it is worth it for convenience. + // Do not propagate to children, as each child of an added branch + // receives its own NOTIFICATION_ENTER_TREE, and this would + // cause unnecessary duplicate resets. + if (is_physics_interpolated_and_enabled()) { + notification(NOTIFICATION_RESET_PHYSICS_INTERPOLATION); + } } break; case NOTIFICATION_MOVED_IN_PARENT: { if (!is_inside_tree()) {