How to display distance between two actors on screen when clicking on one of them...?

I was creating a c++ unreal project. i had an instant where i have to display the distance between two actors on game screen. It is first person game. I have created a HUD with cross hair in the center. There are several static mesh actors placed on the ground. During game play it must display the distance of that actor from another reference object, when i click over it. What should i do. Please help…

Trace from camera position, calculate forward vector based on camera rotation, multiply by the range you want the items to count. Having something as a return value from the trace, get ‘HitActor’ after breaking the result struct trace provides.

Then take that HitActor location, calculate the distance to the second object you need, then either ‘PrintString’ it onto the screen or make a widget, add to the viewport and use TextField ‘SetText’ function to set the actual text that it should display (there are several nice float to text formatting nodes).

The widget itself will be simply a TextBlock put anywhere you wish on the screen. In the PlayerController on BeginPlay just create it, store the reference and call ‘AddToViewport’. You can show/hide it when needed.

I’ve recently made an example trace from camera right ahead in front of it here:

I want the distance displayed when i click over that…what should i do…can u suggest a sample code…plzzzzz…

Or just tell me how to display a message when i click over a static mesh c++ actor…

I am not a programmer. I cannot give you a sample code. I can do that easily in blueprints and I told you how. If you want the distance displayed in-editor and that is what you mean by ‘click’ then I cannot help you since I have no idea how to add widgets to editor viewport or whether it is even possible.

I believe however, that you meant in-game, and that is what I described. What I said would be the way to do it in blueprints. Again, I cannot help you with code, I did quite some C++, but never within the UE4.

Thank U…