The queue system for my project ended up being more complicated to make then I thought. These bugs took a few frustrating evenings to fix, so now I’ve finally fixed them I thought I’d share it so I can move on!
The Queue System
This is where the customers join the queue to use the cash register to make their purchase. The queue for the cash register is made up of box colliders called “queue points”, and when the customer triggers them, they are set to “in use” so another customer doesn’t go to the same one until its available again.
The script on the customer first checks the list of cash registers in the level to see which have an employee on them, and then it looks for the closest cash register and joins that queue if a spot is available.
When the customer joins a queue, a co-routine starts that looks for when the point in front of them is available and when it is they move forward until eventually they are served at the point closest to the register. If they are in the queue for too long though (e.g. because the employee leaves), the customer will leave without making the purchase.
The Problems
- Cutting the queue
The problem started out being that customers were cutting the queue; where if the spot closest to the register was free, they’d go straight to that. The customers further back in the queue would also get stuck, and not be able to move to the front.
- The cause
I found this was because I was setting the “queue point” to “in use” as the customer travelled to it and not when they triggered it. I think I had done this to stop any issues with customers going to the same point at the same time, but it led to weird behaviour where customers would join based on who picked up an item first and not who got to the queue first.
- The solution
I changed this so it was triggered when they got to the queue point and also changed it so they would always join from the last queue point and move forward from there.
2. Game freezing
After making this change, the game started freezing and this was from a customer getting stuck in a loop from searching for an available register. I fixed this but I need to go back and tidy up that script as it didn’t need to be as complicated as I’d written it.
3. Infinite queue
And then finally, everything seemed to be working but the customers started going into a loop where they would be served and join the queue again behind the next customer and then repeat- couldn’t get enough of that queue apparently!
This was quick to fix with a bool value to check against if they’d been served or not, but it was a funny result after everything else that had gone wrong with queueing.
Summary
After fixing this bug the queue works great now and the customer’s behaviour for joining it makes a lot more sense.