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"

Find Array Element by its Index

Soo every now and then i notice that the only way to get a quick return of an Element of an Array would be the Array function "find" /** (Not counting foreach loops as quick even tho it can be very quick executed) */ which takes the Object as a parameter, but why isn't there a function where it takes the index as parameter and returns the Element of the Array that sits at that position? Most of the time i know what the index of the desired Element is but need the object (reference) itself.

E.g.: Lets say i have a Grid (X=11; Y=11) which holds Tiles (11*11= 121 Tiles Total), in an Array, that can spawn a Room, when a player enters a Unknown Room another Room gets Spawned on every adjacent side of the Entered Room. So through a Colision trigger i get the Room with the corresponding Tile, with this Tile i get the index position of it and can determine where in a grid the other tile index are, so i know where they are but i would have to run a ForEachLoop through an array 3 to 4 times even tho i know their position in the array...

(the 4 index are -> CenterTileIndex + 1, CenterTileIndex - 1, CenterTileIndex - X and CenterTileIndex + X (X stands for the Grid axis size) one index we wouldn't need because the Player came from that direction but we would still need to check if we don't pass the where the Player came from Room through)

That's a unnecessary complexity of O(4n) // (4*121 = 484)

instead of 1 and with a nested loop it could easily be O(n²) // (121² = 14641)

So why again isn't there a the functionality find an Element by its Index? You already have the RemoveAt which removes an Element at an Index by passing it an idenx.. so why not a simple FindAt node?

Have a nice day and keep the amazing work up.

Product Version: UE 4.19
Tags:
more ▼

asked Mar 28 '18 at 10:09 PM in Blueprint Scripting

avatar image

TheDarkScience
11 1 2 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Isn’t this just a “GET” node? It does exactly that, it takes your array and you tell it what index to retrieve and it retrieves whatever element is located at that index.

more ▼

answered Mar 29 '18 at 12:09 AM

avatar image

Nebula Games Inc
5.4k 28 9 15

avatar image TheDarkScience Apr 03 '18 at 01:19 PM

Ohhh damn your right, it's displayed as "Get (a copy)" i must have over looked it all the time since i probebly thought it only make a copy of the array instead of giving the reference to the array.

Thanks alot, and here i was thinking all the time they havn't thought of that.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

The Get node should do what you want. Here is a list of all array nodes and what they can/can't do.

more ▼

answered Mar 29 '18 at 11:09 AM

avatar image

Dune
1.9k 53 40 200

avatar image TheDarkScience Mar 30 '18 at 01:08 PM

Thanks alot, seems like i looked at the wrong places, its even shown at WorkingWithArrays which was the one i flick through, mayby i shouldn't try to see if they have documented it at 3 AM

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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