[Solved] Spawning objects/meshes between two points of spherical collision

To start, I’m not the best at blueprints but I know my fair share. But, I was interested in spawning objects between 2 spherical collision boxes. Reason for this is I am creating a space game with 1 main planet, and I don’t want space ships to be spawning too close or inside the planet mesh, as I’d like a specific amount of ships to be in the scene at all times (player collects 1, a new one spawns). I also don’t want to use any box extents because my maps bounds are spherical as well.

So after stirring up some blueprint stew, I created this:
SpawnItems (Function)
I know the cast to inside removal area is not connected, just wanted something to work for right now. Heres what the - Inside Area Removal - looks like so far:
Inside Area Removal (Event Graph)

So after I created those I just did a simple switch on int and then cast to Spawnitems Function, which works perfectly if I was not trying to remove the items inside the other sphere collision.
[SPOILER]Here is what it looks like:



The point of this image is to focus in on the one cube that is inside the red ring (Sphere1, sphere collision). Inside those red rings is where I don’t want the cubes/objects to spawn.
Note: There is 6 cubes in this preview (you can only see 3), for test purposes. Also, please excuse the SpawnArray function, I was testing with arrays. In this working preview, everything was disconnected from that function in order to work.

[/SPOILER]

Please if you have any ideas, send them my way! Thank you!

I’m not sure I can actually find a question here but…

I gather you want to spawn the spaceships inside your sphereical map, but not inside your planets?

So you can get a random point in the map ( I think you have that ), but if that’s inside a planet, calculate again.

What exactly is the problem?

Well, I knew I was forgetting something, but I wanted to spawn them outside of let’s say 500 meters away from the planet as well, hence my use of another spherical collision. My original idea was when each spaceship was created I’d add it to an array. Then, once inside the array it would check if it was in the bounds of Sphere1 (Inner collision) and if so, remove the mesh but it would only allow me to remove it from the array. Which, I’m not completely sure, but if I remove it from the array, would it remove the physical mesh in-game?

So the questions to answer would be:
If I remove the static mesh from the array would it also remove the mesh in game?
How would I go about setting up a set radius for the spaceships not to spawn?
What type of nodes would I be looking at? EX: (Array, loop, etc…)

P.S: Yes I already have the random point and spawn mechanic working. Just need the removal/recalculation of a mesh.

Hi - so, no. Removing it from the array would not remove it from the game, you’d need to use DestroyActor and then remove it from the array.

Rather than spawning and then removing the ones inside the planet, why not spawn them at a minimum distance from the planet centre. That way they will never be in the planet.

Imagine a line extending from the centre of the planet. It can take on any angle, but it’s length must be at least the radius of the planet.

That way you get no ships in the planet, but you still might get ship overlapping, so you have to check before you spawn ‘is there already another ship here?’.

Strangely enough, I have already written some code like this for my game, will paste it here:

So, it’s spawning islands, but you can just change that to spaceships :slight_smile:

Notice, I’m check if the location is already used, that goes like this:

That’s the whole thing! Something to bear in mind though, this is assuming it’s spawning around the origin, you’ll have to tweak it if you want it to work at another point in space.

Sweet! I’ll get to testing it soon but I’m almost certain it will work anyway since the code looks good. I didn’t even think about spawning it from the centre of the planet lol. And yes it’ll work perfectly for my game since there’s only one planet. Thank you again!

Alright so I got to test it out, I copied your nodes down to every variable name, and yet objects/spaceship won’t spawn. I feel like this is just a dumb mistake somewhere inside some variable, but every time I check each variable, function, node, etc I find that all the math and nodes are correct, they just won’t spawn. My construction script is just dragging out the exec to spawn items function, and my event beginPlay has its exec dragged to spawnItems too. Here’s what the rest of my BP looks like:

Spawn Items Function:

Location Used Function:

Note: You can also see my variables and local variables on the left side. And sorry about everything being clumped up, I wanted to get everything in the picture.
Also, inside of the spawnItems function, I tried replacing the random float in range to Random point in bounding box (Sphere1’s collision) and that didn’t work either. But again, they are basically the same thing.

Do it on begin play, not construction.

What’s your max range?

Ok, simplify first. Take out the location check, just get it to spawn on a loop, then re-integrate it :slight_smile:

Alright so it works!, Only thing I ultimately changed was deleting the link in the construction script. Other than that it just worked randomly after re-integrating it. Thanks again!

Excellent :slight_smile:

I am trying to do the same thing, i followed everything you both have been saying but my pawns still end up spawning within the middle/area i dont not want them. Apologies for reviving an old topic, however after googling for days this one the only topic I could find that had to do with what I am trying to do as well.