From e46993f0dbd2e0fe10dacf7745a4d8110a9e22b2 Mon Sep 17 00:00:00 2001
From: lawnjelly <lawnjelly@gmail.com>
Date: Mon, 10 Feb 2025 10:14:50 +0000
Subject: [PATCH] Physics Interpolation - Auto-reset on
 `set_physics_interpolation_mode()`

Fixes historical bug where auto-reset wasn't working correctly.
Also fixes process modes on Cameras when mode is changed.
---
 scene/2d/camera_2d.cpp    | 1 +
 scene/3d/camera_3d.cpp    | 1 +
 scene/main/node.cpp       | 8 ++++----
 scene/main/scene_tree.cpp | 5 +++++
 4 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp
index 2ac935adda0c..8fa1f25746a1 100644
--- a/scene/2d/camera_2d.cpp
+++ b/scene/2d/camera_2d.cpp
@@ -300,6 +300,7 @@ void Camera2D::_notification(int p_what) {
 			// Force the limits etc. to update.
 			_interpolation_data.xform_curr = get_camera_transform();
 			_interpolation_data.xform_prev = _interpolation_data.xform_curr;
+			_update_process_callback();
 		} break;
 
 		case NOTIFICATION_SUSPENDED:
diff --git a/scene/3d/camera_3d.cpp b/scene/3d/camera_3d.cpp
index 28e712704b14..e527ac748f50 100644
--- a/scene/3d/camera_3d.cpp
+++ b/scene/3d/camera_3d.cpp
@@ -230,6 +230,7 @@ void Camera3D::_notification(int p_what) {
 			if (is_inside_tree()) {
 				_interpolation_data.xform_curr = get_global_transform();
 				_interpolation_data.xform_prev = _interpolation_data.xform_curr;
+				_update_process_mode();
 			}
 		} break;
 
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index f5bc3344dd4a..1cd99b79a0e1 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -921,12 +921,12 @@ void Node::set_physics_interpolation_mode(PhysicsInterpolationMode p_mode) {
 		} break;
 	}
 
-	// If swapping from interpolated to non-interpolated, use this as an extra means to cause a reset.
-	if (is_physics_interpolated() && !interpolate && is_inside_tree()) {
+	_propagate_physics_interpolated(interpolate);
+
+	// Auto-reset on changing interpolation mode.
+	if (is_physics_interpolated() && is_inside_tree()) {
 		propagate_notification(NOTIFICATION_RESET_PHYSICS_INTERPOLATION);
 	}
-
-	_propagate_physics_interpolated(interpolate);
 }
 
 void Node::reset_physics_interpolation() {
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index abb6f8ec9071..cd39c520e78f 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -482,6 +482,11 @@ void SceneTree::set_physics_interpolation_enabled(bool p_enabled) {
 
 	_physics_interpolation_enabled = p_enabled;
 	RenderingServer::get_singleton()->set_physics_interpolation_enabled(p_enabled);
+
+	// Perform an auto reset on the root node for convenience for the user.
+	if (root) {
+		root->reset_physics_interpolation();
+	}
 }
 
 bool SceneTree::is_physics_interpolation_enabled() const {