瀏覽代碼

Merge pull request #80289 from lawnjelly/fti_2d_reset_on_enter

[3.x] Physics Interpolation 2D - reset on NOTIFICATION_ENTER_TREE
Rémi Verschelde 2 年之前
父節點
當前提交
95877b8e1f
共有 1 個文件被更改,包括 13 次插入0 次删除
  1. 13 0
      scene/2d/canvas_item.cpp

+ 13 - 0
scene/2d/canvas_item.cpp

@@ -583,6 +583,19 @@ void CanvasItem::_notification(int p_what) {
 			if (!block_transform_notify && !xform_change.in_list()) {
 			if (!block_transform_notify && !xform_change.in_list()) {
 				get_tree()->xform_change_list.add(&xform_change);
 				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;
 		} break;
 		case NOTIFICATION_MOVED_IN_PARENT: {
 		case NOTIFICATION_MOVED_IN_PARENT: {
 			if (!is_inside_tree()) {
 			if (!is_inside_tree()) {