Calling Line Trace in Game State

Hi all,

I have the following code running in my game state at the start of the game to find acceptable locations to spawn AI bots:

The line trace always fails though. Is it meant to not work when called from game state? If so, where should I really be putting this logic?

Should probably put spawn logic on some actor in the level, and have game state or level bp call the function which triggers spawns. Not sure how well game state interacts with world since it’s kinda abstract.

GameState is an actor so it should be fine however its possible it fires say before the landscape has loaded or something.

that said its not a great place because you cant visualize it or edit it easily.

A better example would be to use box collision and then its easy to visualize the bounds in editor and copy/paste if needed. you can also add vector widgets and manually place some in world

As far as I understand, you select a spawn point on the edge of the circle, so the distance of the capsule from the center of the circle will always be the same.

Secondly, your code does not account for the location of the spawn circle, so your enemies always try to spawn at the origin of the world (0,0,0).

Thirdly, you always try to trace from the selected spawn location down to -5000 on the Z-axis. The logic doesn’t just check for a spot 5000 cm below; instead, it checks every centimeter all the way down to -5000 cm. For example, if your spawn point is at +4000 Z, your trace start will be 4000 and the end will be -5000.

Fourthly, you use a line trace rather than a sphere or capsule trace. Because of this, the trace may return true even if the location does not have enough clearance around the spawn point to actually accommodate your enemy.

My best guess is to first check if the trace start and end locations are exactly what you intend. You might be tracing at the wrong location or in the wrong direction, which could lead to unexpected results. After that, you can use the hit actor to detect exactly which actor you hit. If these suggestions don’t solve your problem, or if you have already tried them and they didn’t work, we can dive deeper. Have a nice day!