• News

• Industries

• Learning & Support

• Community

• Marketplace

Spawning Actors on Grid?

Anyone give me some help in working out how to spawn actors on a grid using blueprints.

i can get the actors spawning under mouse cursor using hit result but idealy i would like to get things spawning on a grid so items snap together and not clip through each other or the world… (grid not visible ingame ofcourse)

to get an idea of what i mean ive attached a quick image.

any help would be great. thanks

I recently added Grid Placement of objects in my RTS Game. This is how i did it. Make sure you give a high value for Nearest nth (like 200 or 300 etc).

Create an array of vectors where each vector is one of your grid points. So the first index in your array would be Vector 0x/0y. The next index could be 100x/0Y, then 200x/0y until you need to start the second row at 0x/100y.

If you look in my map generator threads I show a vector field generator that creates such a field with hexagons.

Whenever you spawn your actor you can choose one of those vectors for the spawn transform.

going way over my head lol.

needs to be explained abit more not getting a grasp of it.

here is what i have. and it spawns the actor when i press a key at the cursor location. but ofcourse its not on grid so items dont snap together but overlap each other or go through the floor or wall etc etc.

What they’re suggesting is to use an array to handle your grid and store all possible spawn points in that array (or list since arrays in UE4 are only 1D). When it’s time to spawn, pick a random index from the array and spawn there. To create the array, define the width and height of the grid in variables (max rows & columns), then run two Loops, first on X, then Y (or Y, then X). Example:

``````

For Loop Index=0 through Index=width-1
Set X
For Loop Index=0 through Index=height-1
Set Y
Make Vector (X*100 | Y*100 | Z=0)