Use the UMG blueprint to click the button to obtain the distance between the two characters and display it

Use the UMG blueprint to click the button to obtain the distance between the two characters and display it
As shown below

With as Shown below, you mean WITH the red Line?

Else…
On Button Clicked, you get both Actors and get their World Location.
Now you take the two Vectors of the Locations and use the “Distance (Vector)” Node.

THis returns a float, holding the distance between both Actors in World Space. Just feed a Formated Text with “{dist}cm” and plug the float into the dist Input…

With the red Line:
In your UMG Graph, you find an Override Function for OnPaint (move the mouse a bit right of the “Functions” Label in the Detail Panel, to make the Override Dropdown appear).
In the OnPaint function, get both Actors again, take their World Location and use the ProjectWorldtoScreen Node, to Get the Viewport Positions (Vector2D) of the World Locations.
Now simply use a DrawLine Node, feeding it with both resulting Vector2Ds.