How do I prevent an actor from spawning on another actor?

So in my game, it randomly makes a sphere 6 times in a random location. I do this with the random float node. Every time, that a sphere is destroyed, a new one places. However, sometimes the new one places on an existing sphere, How can I prevent this. I was thinking of making a vector that saves each location and it can’t place on that vector, however it is a float so if it is off by one decimal it can still technically place on an existing sphere. Any ideas? Thanks!

  1. Store the spawn location

  2. Pick the new location and store it. (this needs to be stored because every time you use a random picker it returns a different value)

  3. check if new location distance to old location is greater than sphere radius

  4. if yes, spawn. if no, try again.

Hey, well you have lot of options here… i try to explain some…

  1. Your idea is great, you can store occupied locations and block spawn.
  2. Because we always know the exact size of the spheres you may can do a collision check and decide if sphere is not colliding with other spheres, so you can spawn quickly…
  3. Drop the full “random” location idea and do a semi controlled random location selection. This means: Imagine you have a box with 10,10,10 size. We know sphere diameter is 4. That means if you spawn one sphere at 2,2,2 next valid location can be bigger then 6,2,2 or bigger 2,6,2 or bigger 2,2,6 (in 3d space of course). So technically you can pre calculate the next possible start location which start from x,y,z and ends at 10… in short check for distances :slight_smile:
  4. Making IT DESIGNER FRIENDLY! UE4 blueprints support lot of thing like moving / creating vectors before the game (exposed variables right?), you can create an array of vectors and pre design spawn locations and your spheres can select randomly from this array.

If sphere always should spawn, create a recursive function to make more try’s if spawn is blocked… just be careful, dont create any infinite loop :wink:

Hope this give some ideas :slight_smile:

Thank you for telling me this. I think I have an idea and will let you know.

Hello! Thank you for the answer. Do you think you can show me a blueprint on step number 3? Thanks!

Thanks for telling me this but can you tell me what you defined the radius variable as? Also can you show me where you set the old pos variable?

Well, so basically you obtain your new location (don’t know your method), And store that as the NewPosition. Then compare it to the OldPosition.

If the check passes, spawn and update the value of OldPosition.

If it fails, wait until next frame, and try again.

After Spawning your sphere, set OldPosition from NewPosition, to do the check next time.

Ideally you spawn your 1st sphere with no check. And to avoid a perceptible delay, you could pick the new position immediately after spawning, that way you have a few moments to do so.

So when you need to spawn the new one, the position is already picked, and you just use the NewPosition value.

So I made this bet how do I set the old pos and the radius? Here is my blueprints:

I made this as my blueprint but how would I set the old pos and the radius to? Thanks! Here is my BP: