I’m using Target Points to spawn a Blueprint item at random locations every 2 seconds. The system picks a random Target Point and spawns the item there.
However, I’m facing an issue: sometimes two items spawn at the same location, overlapping each other. This looks really awkward and messy in the game.
Is there a good way to prevent items from spawning at the same spot if an item is already there?
When it selects the random spawn point, call “get overlapping actors”, if it comes back overlapping an actor of the spawned blueprint class, loop back and select a different random point
I suggest you keep track of the spawn points that were already used. Instead of building a temporary array every time SpawnRandom is called, can you make an array variable as part of your Blueprint?
Then, when a point is used, your can remove it from the array.
Instead of using a custom event for your timer, you can use a function. That will allow you to make RandIndex a local variable of this function, which isn’t possible with custom events. Take a look at Set Timer By Function Name.
This setup lets you add new spawn points to the array at any time, if you need to (not limited to BeginPlay). You can even re-add the already used spawn points later, if you want. You can keep track of the used spawn points like so (this is the same as above, in a function, but with an extra array holding the spawn points that were used):