Infinite Loop and enemy spawner

I’m trying to create an enemy spawner that selects random points within this inner red box and spawns enemies. However, this function must guarantee that X enemies will be spawned in valid locations (locations that have navigationData). I created the entire system, but this part of ensuring that all X enemies are spawned is creating an infinite loop, because if the enemy failed to be spawned (It occurs when trying to spawn in a location without navigation data, like this internal area of ​​the print where I placed some objects and a navmeshvolume creating a negative space in the navmesh), it calls the function again, until it manages to spawn ALL X enemies. How can I do this in a way that doesn’t give me an infinite loop error every time I press play?

I recently made a spawner system, and I used EQS as the point generator, which includes a lot of functionality that might be useful for such cases, including projection to the navmesh

The EQS would generate quite a few points (I had spawners covering areas of more than 50x50m), out of which I would pick the number of creatures I wanted to spawn

The benefit of doing it with EQS is you can have one spawner that can be reused with different spawn location patterns, and you can set up quite specific patterns using the already existing tests available for point filtering

Technically you can still face the same issue where not enough valid points are returned, depending on your generator setup, but I think it will be considerably less likely

1 Like

Thanks, it worked perfectly!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.