x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.20
Tags:
more ▼

asked Nov 10 '18 at 08:28 PM in Blueprint Scripting

avatar image

xGameSlave
11 2 4

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Nov 10 '18 at 10:10 PM

avatar image

GarettHunter
35 2 4 8

avatar image xGameSlave Nov 11 '18 at 05:09 AM

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.alt text

screenshot-356.png (72.2 kB)
avatar image GarettHunter Nov 18 '18 at 07:59 AM

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 arrays

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.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question