• News

• Industries

• Learning & Support

• Community

• Marketplace

# Saving position of specific actors in a world?

Hey, everyone. Is there a way that I can store/save the positions of specific actors in the world into an array? E.g. I have some cubes throughout the world and I will be spawning more of it soon thru a file online. However, I need to know if before I spawn another cube, the supposed spawn area of the cube isn’t occupied by another cube. Let’s say that Cube_1 is already in the world, but Cube_2 is about to be spawned, Cube_1 location is 10.5, 9, 7 and Cube_2 is 10,9,7, Cube_2 should not be spawned.

I thought of using the GetAllActorsofClass node in finding the actors that have spawned already and store them in an array and then add the new data coming in to a new array and compare both. Check if there’s data <= or >= from Array_1 to Array_2, but that’s as far as I can go. Is there a node that checks if the spawn location of an actor is within the bounds of another actor?

Defintely DON’T do GetAllActors every time you want to spawn

When you spawn the objects, you can keep a record of where you put them, just an array of vectors. If you already have objects from a previous spawn, you can use GetAllActors once to record all the positions.

Then, in your spawn loop, you have to check if the location ( or near it ) has been used before you do the spawn.

Thank you for your reply! Is there a way to compare the two arrays? Like if vector Array_01 has a cube that has the same coordinates with a cube on Array_02, it wouldn’t spawn the cube anymore?

You basically have to loop through the array looking to see if the position is already taken.

Also, unless you’re using exact positions, you’ll need to check if any of the used positions are within a certain distance of where you’re thinking of spawning.

Need to also consider the size of the array. Loops are Tick/Frame bound, meaning if the array is large it will decrease FPS.

If possible create a grid based system where each grid section gets its own cube array. This will result in smaller arrays to iterate/search.