How can I modify Random Meshes blueprint example to avoid meshes overlapping?

Hi, total noob here. Title says it all.

I have an array of static meshes and I want to spawn them randomly inside a certain radius without overlapping.
As per screenshot I have achieved everything but the overlapping part. How can I do this easily?

Easy way would be to make Them own actors. In your spawnActorFromClass you can select that the engine should adjust the Position If they collide in Spawn. So I would suggest a “spawnerBP” with your Logic Out inside the Level and in beginPlay Spawn your meshActors BPs

Thank you for the answer. I’ll give it a try :slight_smile:

Sorry if I bother you, can you expand on the answer you gave with a little more detail? I’m a little lost to a lot of the concepts. I’m really a newbie in the field (I’m actually a data scientist who is trying to build a synthetic dataset through UE).

I came up with this. Apart from the fact that I cannot remove the actors once spawned, my meshes are still overlapping. What am I doing wrong?

Looking at what you have come up with, due to Adnoh’s answer: Here are some thoughts:

  1. You can use the For Each node and run it over the Meshes To Spawn Array to streamline the process of spawning all the meshes.
  2. You do not need to add a Static Mesh Component to the Static Mesh Actor, that already exists. (drag a line off the spawn return value, in the search window type “get static mesh component” and scroll all the way down, select the highlighted variable, then plug the resulting node into the Set Static Mesh Target) (EDIT: or just plug the return value directly into the Set Static Mesh Target, the editor should “convert” properly)
  3. To remove the Actors you should store them in an Array and use the For Each node again, calling the Destroy Actor node for each of them. (Since the Begin Play Event is called once the Flip Flop will not call the Destroy Actor.)
  4. The problem with the overlapping is (probably) caused by the collisions not being set at the time of spawning the actor. You assign the mesh later, thus the collision overlap happens too late for the Spawn Actor node to handle it. You can try spawning all actors at (0,0,0) and using the Teleport node to bring them to the random location. This node checks for collisions as well.

Hope this helps.