Hi,
Those are good questions. Theoretically, we could have returned the reference to the pathPrefab. However, in object-oriented programming (OOP), that’s considered bad practice because everything that has got a reference to the object assigned to pathPrefab could manipulate it. To prevent that from happening, we create a new list with all waypoints.
If something removes one element from that new list, it won’t affect other parts of our game because we still have the unmodified pathPrefab list.
Did this make sense?
See also:
- Forum User Guides : How to mark a topic as solved