Why is my Queue pf nodes being emptied?
So I'm working on a tower defense type game. I have structures that can spawn units. When a structure is built, it gets a path from the path finding system so that it can pass that path onto new units who will follow that path to the opponents base. That way I don't have to run the path finding algorithm every time a unit spawns. I update the structures spawnPath if any other structure is built.
However, something strange is happening with the spawnPath Queue. Everything appears to work as intended but units are passed the spawnPath at creation and they seem to be sharing the spawnPath instead of creating a unique copy. A unit follows the spawnPath Queue by dequeuing a node and setting it as the way point. As you can see, this is a problem because while that first unit will complete the path, the rest of the units start with an empty queue. I'm not sure what's the best way to remedy this.
I mean, obviously I could create a temporary Node[] array and hold the nodes there then each time before spawning a unit I could put the nodes back into a newly created queue but I feel like I'm missing something and there's an easier way to avoid the dequeing problem.
Your answer
Follow this Question
Related Questions
Make an object move from Point A to Point B then back to Point A repeating 9 Answers
[Help] how do I reference/access another script in unity C# 2 Answers
The name `FindObjectOfType' does not exist in the current context 2 Answers
NullReferenceException problems. 0 Answers
Launching local Unity API Reference from MonoDevelop on Linux 0 Answers