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?
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 (Doubly linked list - Wikipedia) 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 (Circular buffer - Wikipedia), 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.
I am sorry, I only understand blueprinting. I am trying to essentially spawn a child actor “waypoint” in my road tiles. Then, in the waypoint BP, when it is spawned, it should add itself to the list of arrays. This is where I am stuck. I do not know how to add the waypoint to the AI car’s array of waypoints.
Sorry, it got a little busy for me. Assuming there is only one AI car, it is guaranteed to exist, and there is no multiplayer or this runs on the server only, then it appears that this waypoint is being added to the WaypointReferences array of the AI car. However, you say
it should add itself to the list of
which sounds like there is more than one array or something like that.
I don’t think I actually understand what is not working because it seems like this blueprint would add the waypoint to the AI car’s array of waypoints.
I looked back at the main question and it says this
The AI cars are set to follow
waypoints in an array, one to another.
The list of arrays statement makes more sense to me now since the waypoint BP only considers 1 car and not all cars. So perhaps you need to iterate over all AI cars using a for loop on the array returned from “Get All Actors of Class”.
Sorry, I’m just kind of guessing at what might be wrong.