I completed the Laser Defender project following Rick’s instructions and everything was working as expected. When I went back to polish and customize, I ran into issues with pathing.
GOAL
I wanted to spawn two enemy waves simultaneously, so I created a second Enemy Spawner, which worked just fine. Somehow, when I was updating my enemy sprites, it stopped working, and now only one wave will spawn.
IMPLEMENTATION:
- Create two unique enemies prefabs named Ninja and Fangs,
- create two unique paths, one for each enemy,
- create two wave configs, one for each enemy,
- and create two enemy spawners.
On the Fangs WaveConfig, I attached the Fangs enemy prefab, and Fangs path. I then hooked the Wave Config up to one of the enemy spawners. Likewise, I hooked up the Ninja enemy prefab to the Ninja Wave Config, along with the Ninja path. I attached this to the second enemy spawner.
Observed Result
Only the Ninja wave spawns.
Expected Result:
Both the Ninja and Fangs wave would spawn.
I’m pretty sure I’ve narrowed this down to an issue with the path. I have not made any changes to the Enemy, Enemy Pathing, or Enemy Spawner scripts.
To rule out the enemy spawners as an issue, I opened the Enemy Spawner that was supposed to spawn Fangs and swapped the Fangs Wave Config for the Ninja Wave Config. Ninja spawned properly. I opened the Enemy Spawner that spawned Ninja correctly and changed swapped the Ninja Wave Config for the Fangs wave config. Fangs still did not spawn. This told me the issue was Fangs specifically.
Next, I looked at the Fangs Wave Config. The Fangs Enemy Prefab and Fangs path were set correctly. I swapped out the Fangs Enemy Prefab for the Ninja Enemy Prefab, but nothing spawned. I then swapped out the Ninja path for the Fangs path, and the enemy spawned as expected. Finally, I reverted back to the Fangs enemy prefab and found the Fangs would move along Ninja’s path.
THE ALMOST FIX…
I thought this might be a prefab issue because I’d encountered issues with prefabs and the Canvas in the past. I deleted the Ninja path prefab and started again from scratch.
- I created an Empty Game Object called Fangs Path 1
- I created child Game Objects under Fangs Path 1 called Waypoint (0), Waypoint (1) … and so on.
- I dragged Fangs Path 1 into the prefab folder and hooked it up to the Fangs Wave Config.
- I hooked up the Fangs wave Config to an enemy spawner, and it worked!
Both enemies were spawning… and then I broke it…
I noticed my enemies intersected mid-flight, so I changed the position of one of the waypoints on the Ninja path. I applied the change to the prefab and now Ninja won’t spawn. I tried repeating my previous steps with no luck. I even deleted the Ninja Path, and Ninja Wave Config prefabs, and created them both again, brand new. Still no luck.
I have a headache…