Adding to Array in realtime?
So I am making this simple game, it is basically an endless racer where the track is procedural generated and the cars race along the track. The AI cars are set to follow waypoints in an array, one to another. My question is, how can I keep adding waypoints to the array while removing old ones? Is this possible in unreal?
asked Nov 10 '18 at 08:28 PM in Blueprint Scripting
I assume you are concerned with removing elements from an array and having to deal with the elements in the array being re positioned or adding to the array and having to deal with the array resizing. A couple of thoughts come to mind.
Let's assume you only need access to the front and end of this waypoint list, and that you are adding to or removing from either the end or front without needing to access the elements in between. In this case something like a doubly linked list (https://en.wikipedia.org/wiki/Doubly_linked_list) would work well.
However, if for some reason you require quick access to the i'th index of the array and you have a finite amount of waypoints, then you might be able to use a circular buffer (https://en.wikipedia.org/wiki/Circular_buffer), but I think you might need to make one on top of the array.
Unfortunately I do not know the constraints of the racing game to determine if either would work.
Follow this question
Once you sign in you will be able to subscribe for any updates here