Forum begins after the advertisement:
[Part 12] Enemy Spawner messed up
Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [Part 12] Enemy Spawner messed up
- This topic has 4 replies, 3 voices, and was last updated 1 week, 4 days ago by
Alp Apustaja.
-
AuthorPosts
-
August 17, 2025 at 10:37 pm #18638::
I am following this series for some time and everything’s working, but when i reached this part my enemy spawner started to spawn just the first wave then stop. it was working fine before that but since then it has stopped. funny thing is that we havent changed the enemy spawner script since before it got broke. any ideas of what could be happening and how to fix it? . this video is about weapon evolution and ive revamped the system with the part 15 already but this issue was not fixed. i dont even know which scripts to paste here
will leave the enemyspawner code here anyways
using NUnit.Framework; using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemySpawner : MonoBehaviour { [System.Serializable] public class Wave { public string waveName; public List<EnemyGroup> enemyGroups; //list of groups of enemies to spawn in this wave public int waveQuota; //total number of enemies spawned in this wave public float spawnInterval; //the interval at which to spawn enemies public int spawnCount; //number of enemies already spawned in this wave } [System.Serializable] public class EnemyGroup { public string enemyName; public int enemyCount; //number of enemies to spawn in this wave public int spawnCount; //number of enemies of this type already spawned in this wave public GameObject enemyPrefab; } public List<Wave> waves; //a list of all the waves in the game public int currentWaveCount; //the index of the current wave (starts from 0) [Header("Spawner Attributes")] float spawnTimer; //how long between each spawn public int enemiesAlive; public int maxEnemiesAllowed; //max number of enemies allowed on the map at once public bool maxEnemiesReached = false; public float waveInterval; //interval between each wave bool isWaveActive = false; [Header("Spawn Positions")] public List<Transform> relativeSpawnPoints; // a list to store all the relative spawn positions Transform player; void Start() { player = FindFirstObjectByType<PlayerStats>().transform; CalculateWaveQuota(); } void Update() { //check if wave has ended and next wave should start if(currentWaveCount < waves.Count && waves[currentWaveCount].spawnCount == 0 && !isWaveActive) { StartCoroutine(BeginNextWave()); } spawnTimer += Time.deltaTime; //check if its time to spawn the next enemy if(spawnTimer >= waves[currentWaveCount].spawnInterval) { spawnTimer = 0; SpawnEnemies(); } } IEnumerator BeginNextWave() { isWaveActive = true; //waveInterval seconds before starting next wave yield return new WaitForSeconds(waveInterval); //if there are more waves to start after current wave, move on to the next wave if(currentWaveCount < waves.Count - 1) { isWaveActive = false; currentWaveCount++; CalculateWaveQuota(); } } void CalculateWaveQuota() { int currentWaveQuota = 0; foreach (var enemyGroup in waves[currentWaveCount].enemyGroups) { currentWaveQuota += enemyGroup.enemyCount; } waves[currentWaveCount].waveQuota = currentWaveQuota; } /// <summary> /// this method will stop spawning enemies if the amount has reached its maximum /// </summary> void SpawnEnemies() { //check if the minimum number of enemies in the wave have been spawned if (waves[currentWaveCount].spawnCount < waves[currentWaveCount].waveQuota && !maxEnemiesReached) { //spawn each type of enemy until the quota is filled foreach (var enemyGroup in waves[currentWaveCount].enemyGroups) { //check if the minimum number of enemies of this type have been spawned if(enemyGroup.spawnCount < enemyGroup.enemyCount) { //defines the location of spawning the enemies out of the screen Instantiate(enemyGroup.enemyPrefab, player.position + relativeSpawnPoints[Random.Range(0, relativeSpawnPoints.Count)].position, Quaternion.identity); enemyGroup.spawnCount++; waves[currentWaveCount].spawnCount++; enemiesAlive++; //limit the number of enemies that can be spawned at once if (enemiesAlive >= maxEnemiesAllowed) { maxEnemiesReached = true; return; } } } } } //call this function when an enemy is killed public void OnEnemyKilled() { //decrease the number of enemies alive enemiesAlive--; //reset maxEnemiesReached flag to false if number of enemies alive has dropped below max amount if (enemiesAlive < maxEnemiesAllowed) { maxEnemiesReached = false; } } }
August 17, 2025 at 11:31 pm #18641::There shouldn’t have been any changes to the
EnemySpawner
script in Part 15. I suspect the issue might’ve been some of your Inspector settings.@Alp.Apustaja can you highlight some of the key settings Bruno has to look out for in the Inspector if his EnemySpawner is only spawning 1 wave?
August 17, 2025 at 11:36 pm #18643August 17, 2025 at 11:39 pm #18644::No problem bruno :) let’s see what the AI says. It is trained with all the content from the series so it is much faster at spotting issues / errors than I am.
August 18, 2025 at 1:35 am #18650::Based on the reference information and the provided script, here are key Inspector settings to check:
- Waves List
- Ensure multiple waves are actually configured
- Check that each wave has:
- Populated enemyGroups
- Correct waveQuota
- Proper spawnInterval
- Wave Spawning Parameters
- maxEnemiesAllowed: Verify it’s set high enough to allow multiple wave spawns
- waveInterval: Make sure it’s not set too high, preventing wave progression
- relativeSpawnPoints: Confirm spawn points are assigned
- Enemy Group Configuration
- Each enemyGroup should have:
- A valid enemyPrefab
- Correct enemyCount
- Matching enemyCount and spawnCount logic
These settings are critical to ensure the EnemySpawner can progress through multiple waves successfully.
has upvoted this post. August 18, 2025 at 1:40 am #18653::Could you clarify a few details about your wave configuration in the Unity Inspector?
- How many waves have you set up?
- What are the specific enemy counts for each wave?
- What value do you have set for maxEnemiesAllowed?
- Have you confirmed that the OnEnemyKilled() method is being called when enemies die?
These details will help diagnose why your enemy spawner might be stopping after the first wave.
August 18, 2025 at 2:57 am #18666August 18, 2025 at 3:00 am #18667::The reference information highlights that the maxEnemiesAllowed parameter directly impacts enemy spawning. When this value is set too low, it can prematurely halt the enemy spawning process by triggering the maxEnemiesReached flag. Increasing this value allows more enemies to spawn simultaneously, resolving the wave progression issue.
has upvoted this post. -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: