Getting a random point in an aiming reticle

I’m looking to have a shotgun that fires multiple pellets randomly within the range of a circle reticle in the centre of the screen. So if I have a circle on screen, can I get a random point in that circle and then project it into world space to end the end point of the ray trace?

Getting the random point within a radius isn’t too much of a problem. The issues is getting a random point within a radius in a UMG widget and then projecting that point from screen space to world space.

May be RandomUnitVectorinCone

will help you.

So I figured out a way to do it in my widget graph.
It looks a little like this. It’s worth pointing out that the radius of my reticle is 50 units when the preview resolution is 1920x1080. Hence why the first random number between 0 and 50 and the vector is divided by 1920 and 1080 before being multiplied by the viewport size.

So for actually firing the weapon in code, I called this function through a blueprint implementable event in C++. I used the location of the end of my weapon mesh for the start of the line trace, and for the end I took the world location and added the direction multiplied by the weapon range.

Works perfectly.