I created this BP to generate a random vector location, ask if it is outside of a certain distance of another vector location and if so add it to the array, otherwise remove it. I also added logic to save the first generated location from being removed, otherwise it would always remove the first vector from the array and never add anything.
The goal here was ultimately to create a function where I could plug in specific variables such as: max spawn count. Then to output and array to spawn any actor I want and not have them overlap one another.
So what is happening at the current state is that it generates the array, but the spawns still can overlap.
I’ve also realized that if I crank the distance up, it seems to only spawn in the same corner. As if the for loop is only checking the distance from one corner of the predetermined spawn location (set with the coordinates in the beginning of the BP)
I’m thinking I’m using the nested for loop incorrectly or I am assuming incorrectly how it is checking the distance.
I’m seeing a possible flaw, technically because I’m adding the new location to the final spawns array, then looping through the array, it still may always remove itself because it will check it self last and fail the check, then executing the false logic to remove itself.
The only odd thing is, the array still fills mostly up and will spawn the actors. Randomly, just still too close to one another in some cases
Also please note that although the screenshot shows it’s checking the distance value is greater than 1. I normally have it set much higher. The 1 was temporary for debugging
I’m not going to be much help in DIRECTLY solving your issue, however, I find that fellow developers tend to run into all sorts of issues because they are using FOR/WHILE/DO Loops incorrectly/casually/too often.
I learned C++ before learning Unreal, and unless the parameters are 100% airtight, you WILL run into issues.
I avoid FOR/WHILE/DO Loops as much as possible, and only use them for grabbing large groups of assets (i.e. save parameters, actors of shared heritage, etc.), NOT to perform general programming.
Try doing this manually (creating your own loop), without the loop function, and see if it works.
I managed to get this working using a boolean that is either set true or false based on meeting the criteria or not. then once completed uses the final spawn array to spawn the actors.