Skip to content

Commit

Permalink
Physics Interpolation 2D - reset on NOTIFICATION_ENTER_TREE
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lawnjelly committed Aug 5, 2023
1 parent b776cf5 commit bcfca5e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions scene/2d/canvas_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit bcfca5e

Please sign in to comment.