How to raytrace in c++

What you need to search for is “UE4 line trace c++”

Here is a tutorial on using line traces in c++ that you might find useful:

https://unrealcpp.com/line-trace-on-tick/

and if you are really serious about learning c++ with UE4 there is two must take courses on udemy that are fantastic. One by a former epic employee Tom Looman.

https://www.udemy.com/unrealengine-cpp/learn/v4/overview

https://www.udemy.com/unrealcourse/learn/v4/overview