Browse Source

Physics Interpolation - fix continuous updating in unmoving objects

Adds instances to the transform update list as well as the interpolate update list when unhiding them. This ensures that the system auto-detects non-moving objects, and removes them from the interpolate update list on the next tick, preventing unnecessary updates.
lawnjelly 3 years ago
parent
commit
e4f252d94f
1 changed files with 9 additions and 0 deletions
  1. 9 0
      servers/visual/visual_server_scene.cpp

+ 9 - 0
servers/visual/visual_server_scene.cpp

@@ -1159,6 +1159,15 @@ void VisualServerScene::instance_set_visible(RID p_instance, bool p_visible) {
 		_interpolation_data.instance_interpolate_update_list.push_back(p_instance);
 		instance->on_interpolate_list = true;
 		_instance_queue_update(instance, true);
+
+		// We must also place on the transform update list for a tick, so the system
+		// can auto-detect if the instance is no longer moving, and remove from the interpolate lists again.
+		// If this step is ignored, an unmoving instance could remain on the interpolate lists indefinitely
+		// (or rather until the object is deleted) and cause unnecessary updates and drawcalls.
+		if (!instance->on_interpolate_transform_list) {
+			_interpolation_data.instance_transform_update_list_curr->push_back(p_instance);
+			instance->on_interpolate_transform_list = true;
+		}
 	}
 
 	// give the opportunity for the spatial partitioning scene to use a special implementation of visibility