Trouble with Paths

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:

  1. Create two unique enemies prefabs named Ninja and Fangs,
  2. create two unique paths, one for each enemy,
  3. create two wave configs, one for each enemy,
  4. 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.

  1. I created an Empty Game Object called Fangs Path 1
  2. I created child Game Objects under Fangs Path 1 called Waypoint (0), Waypoint (1) … and so on.
  3. I dragged Fangs Path 1 into the prefab folder and hooked it up to the Fangs Wave Config.
  4. 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… :persevere:

ORIGINAL ISSUE:
I wanted to have two waves spawning simultaneously, which I accomplished by using two Enemy Spawners. However, I encountered an issue where, randomly, certain waves would stop spawning.

TLDR; I placed the first waypoint of the path outside of the game camera so the enemies didn’t just “pop into existence,” but I placed it in the Shredder, which, as designed, killed the waypoint before an enemy could spawn.

THE LEARNING PROCESS
Last night I narrowed the problem down to the path itself by swapping out problematic prefabs and wave configs with known-working ones. Eventually found that when I set a certain path on the wave config, spawning would fail.

I recreated the path from scratch and it started working, so I made the assumption that something funky happened with the prefab. I made a slight adjustment to the wave that had always been working, and suddenly it stopped spawning too.

I made the incorrect assumption that there was nothing different between the original “bad path” and the one I recreated. This cost me two hours of trial and error with paths and prefabs, thinking I found a Unity bug.

I turned in for the night feeling completely defeated, but when I sat down today with a fresh set of eyes I solved the problem in a matter of minutes… I looked at the paths and immediately realized my previous assumption was wrong.

The path that had originally been broken was placed outside of the game camera… directly on top of the shredder. This also explained why paths that had been working at one time, would suddenly “break”. I moved the Shredder above the first waypoint, and the wave spawned as expected.

Feeling a little silly, but trying to focus on the fact that at least I figured it out!

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

Privacy & Terms