Hello, Ken,
There are ways to spawn random actors at random locations in the level. The thing is that you need some way to tell the engine what areas you are interested to spawn in, so you can get interesting content that matches what you are imagining as a designer. Absolutely random location will seem just like that, random. And where is the level design in that? An ultra smart system that accounts for all your level variables will be very complicated to produce and probably harder and less flexible than just putting some manual areas of interest in your level.
That doesn’t mean that you need a spawn point per coin either. There are many ways to go around this. You can create volumes (think of them as spawn volumes instead of points) inside of which your coins will apear at random locations, maybe with fixed distances between them (so like a grid). But now you are spawning at specially designated areas.
Inside those areas, you can do traces into the ground, so you can get the exact location at which you want to spawn, and also maybe compare the impact normal so you can limit your spawns to only appear when the ground is flat, or maybe within a slope that is not inaccessible to the player.
You can also build your spawn algorithm in a way that it has a bias to the center, or the edges of the area. Maybe so it tries to make lines on a certain axis once it chooses a starting point.
Another way to go around this would be to have a spawn actor that has a lot of spline components inside. You could put your splines manually along the paths where you might want your coins to appear, so you can manually design the shape of those potential coins within the level. Then you get chose some random indexes out of an array made out of your spline components, and spawn coins at certain distances along the chosen splines. Maybe combining that with a trace to the floor so you don’t have to be as careful with their location and can deploy them a bit faster.
Finally, you can do an all random spawn actor, that gets a lot of locations within your level, makes some tests to check if they are valid, and spawns at those points, either single coins or clusters. But the shapes and interesting variations that you get out of that will be completely dependent on the complexity of your universal spawn actor. For things that are only secondary set dressing and that don’t need to have a lot of control (a trash placer, for example) this could work quite well.
The key for the flexibility you are looking for is doing a trace to the ground, and starting it from a point that you know is above your level. Doing this, any point that you generate in any way will work for you because you will spawn at the location corresponding vertically to your random point but at ground height. And also testing the location against some parameters (what is the slope angle? am I colliding with something different than the floor?) that will help you further refine your generated locations.
In any case, you will have a spawn actor. It doesn’t have to be a point, it can be an area defined by a collision box, a series of splines, or even an actor which location doesn’t matter at all. There can be a lot of spawners in your level, or you can have only one with different components defining your areas inside. Eventually you will get some points, at which you will call the “Spawn actor of class”, with a reference to the class of your coin.
I hope this helps to give an overview on the many ways to accomplish this. In the end, it all comes down to your implementation.