Check if spawn point is empty

I’m trying to figure out how to check if spawn point is empty, so I can spawn new entity there. Still not sure how to do it.

For example:

First step
I have 3 spawn points.

function init(self)
	local n = self.maxPoints
	local spawnPoints = {}
	for i = 0, n-1 do
		spawnPoints[i] = go.get_world_position("spawnpoint" .. i .. "")
	end
end

Second step
If I want to spawn a new entity, I pick one and spawn it.

factory.create("level_script#entity", spawnPoints[math.random(#spawnPoints)])

Next step
Now I have only 2 empty spawn points left and I want to spawn new entities only at non-occupied SPs.

How can check if it’s empty or not?

1 Like

Could you perhaps check for collisions against an invisible GO that represents the actual spawnpoint?

2 Likes

Yeah, that’s what I’m trying to do. My spawnpoints are invisible GOs with a collision. Questions is how can I check collisions between SP and entity before I actually spawn an entity?
Or maybe I misunderstand something?

1 Like

Create a GameObject “SpawnPoint” that has a collision with the GameObject “Entity”. On each update, check if SpawnPoint has a collision with Entity, if there is no collision, spawn a new Entity at the position of SpawnPoint.

2 Likes

Questions is how can I check collisions between SP and entity before I actually spawn an entity

Well, you would check if other entities are occupying the space.

I’d recommend using a trigger, which gives you enter/exit messages. So, when you spawn an entity, you immediately set the state to entered.

3 Likes