Repository: godotengine/godot
File: editor/scene/3d/path_3d_editor_plugin.cpp (C++)

Code before:
				if (ss) {
					PhysicsDirectSpaceState3D::RayParameters ray_params;
					PhysicsDirectSpaceState3D::RayResult result;
					ray_params.from = _edit.click_ray_pos;
					ray_params.to = ray_params.from + _edit.click_ray_dir;
					if (ss->intersect_ray(ray_params, result)) {
						ur->create_action(TTR("Add Point to Curve"));
						ur->add_do_method(c.ptr(), "add_point", it.xform(result.position), Vector3(), Vector3(), -1);
						ur->add_undo_method(c.ptr(), "remove_point", c->get_point_count());
						ur->commit_action();
					}
				}
			}
			if (_edit.waiting_handle_physics) {
				_edit.in_physics_frame = true;

				// Find gizmo reference
				Vector<Ref<Node3DGizmo>> gizmos = path->get_gizmos();
				for (int i = 0; i < gizmos.size(); i++) {
					Ref<EditorNode3DGizmo> seg = gizmos[i];

					if (seg.is_null()) {
						continue;
					}
					_edit.gizmo = seg;
					break;
				}

				_edit.gizmo->set_handle(_edit.gizmo_handle, _edit.gizmo_handle_secondary, _edit.gizmo_camera, _edit.mouse_pos);
				_edit.in_physics_frame = false;
				_edit.waiting_handle_physics = false;
			}
		}
	}
}

void Path3DEditorPlugin::_bind_methods() {
	ClassDB::bind_method(D_METHOD("_update_toolbar"), &Path3DEditorPlugin::_update_toolbar);
	ClassDB::bind_method(D_METHOD("_clear_curve_points"), &Path3DEditorPlugin::_clear_curve_points);
	ClassDB::bind_method(D_METHOD("_restore_curve_points"), &Path3DEditorPlugin::_restore_curve_points);
}

Path3DEditorPlugin::Path3DEditorPlugin() {
	singleton = this;
	mirror_handle_angle = true;
	mirror_handle_length = true;

	disk_size = EDITOR_GET("editors/3d_gizmos/gizmo_settings/path3d_tilt_disk_size");

	Ref<Path3DGizmoPlugin> gizmo_plugin = memnew(Path3DGizmoPlugin(disk_size));
	Node3DEditor::get_singleton()->add_gizmo_plugin(gizmo_plugin);

Review comment (suggestion):
```suggestion
				for (Ref<EditorNode3DGizmo> seg : gizmos) {
					if (seg.is_valid()) {
						_edit.gizmo = seg;
						break;
					}
```

Code after:

			if (!EditorSettings::get_singleton()->check_changed_settings_in_group("editors/3d_gizmos/gizmo_settings")) {
				return;
			}

			path->update_gizmos();
		} break;
		case NOTIFICATION_PHYSICS_PROCESS: {
			if (_edit.waiting_point_physics) {
				_edit.waiting_point_physics = false;
				const Transform3D gt = path->get_global_transform();
				const Transform3D it = gt.affine_inverse();
				Ref<Curve3D> c = path->get_curve();
				EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
				PhysicsDirectSpaceState3D *ss = get_tree()->get_root()->get_world_3d()->get_direct_space_state();
				if (ss) {
					PhysicsDirectSpaceState3D::RayParameters ray_params;
					PhysicsDirectSpaceState3D::RayResult result;
					ray_params.from = _edit.click_ray_pos;
					ray_params.to = ray_params.from + _edit.click_ray_dir;
					bool hit_something = false;
					Vector3 inters;
					if (ss->intersect_ray(ray_params, result)) {
						inters = result.position;
						hit_something = true;
					} else {
						Plane p(_edit.gizmo_camera->get_transform().basis.get_column(2), _edit.origin);
						if (p.intersects_ray(ray_params.from, _edit.click_ray_dir, &inters)) {
							hit_something = true;
						}
					}
					if (hit_something) {
						ur->create_action(TTR("Add Point to Curve"));
						ur->add_do_method(c.ptr(), "add_point", it.xform(inters), Vector3(), Vector3(), -1);
						ur->add_undo_method(c.ptr(), "remove_point", c->get_point_count());
						ur->commit_action();
					}
				}
			}
			if (_edit.waiting_handle_physics) {
				_edit.in_physics_frame = true;

				// Find gizmo reference.
				Vector<Ref<Node3DGizmo>> gizmos = path->get_gizmos();
				for (Ref<EditorNode3DGizmo> seg : gizmos) {
					if (seg.is_valid()) {
						_edit.gizmo = seg;
						break;
					}
				}