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"

How can I sort items in array by properties?

How can I sort items in array by properties (for example item size or location)? Thanks!

Product Version: Not Selected
more ▼

asked Apr 20 '14 at 09:23 PM in Blueprint Scripting

avatar image

36 1 2 7

avatar image $1.99 Taco Combo Jun 25 '14 at 05:53 AM

I'm having the same problem. The answers mentioned here only help me filter for specific item types. I'd love to be able to resort the array (or build a new one) based on something more basic (like x-coord, scale, etc) like the original poster asked.

avatar image Steve Allison STAFF Jun 25 '14 at 06:36 PM

Do you mean something like an array of structs that have multiple entries that could be sorted on or just like a single array of vectors or strings? Or do you mean either scenario? There's no one-shot solution to cover all of those scenarios based on the number of factors that could go into a sort.

avatar image $1.99 Taco Combo Jun 26 '14 at 05:21 AM

It's funny how finally giving in and asking for help led me to figuring it out finally! I really wish there was at least a built in sorting command for an array of things like floats, or ints. I understand an array of actors (like I used) might be crazy to build a "one size fits all" kind of function.

Attached is how I sorted an array of actors by their x-coordinates. I wish I could explain it clearly, but all I did was copy some sorting algorithm on Wikipedia and renaming the variables they used, then hammered at it a bit to make it work on actors instead of numbers. You could tweak it to evaluate any property of the actors instead of X.

alt text

sort_actors_byx.jpg (208.2 kB)
avatar image Benni.Lodge Mar 06 '17 at 12:14 PM

Thanks Taco. I get the feeling this is a frequently visited thread. Here's my take on your BP, for sorting an array of actors by horizontal distance to the Player. Cheers for pointing me in the right direction. alt text

avatar image lixx3r Nov 24 '17 at 02:59 PM

Thanks Benni!! Your code helped me so much. Been stuck for more than 4 hours, and with this code i solved it in 10 min haha. Thanks thanks thanks!!!

avatar image Hitpawz Nov 19 '14 at 03:01 AM

There's no one-shot solution to cover all of those scenarios based on the number of factors that could go into a sort.

This is how I do it in Action Script:

 var HostServer:Object = {Server:"Test", IP:"", Mode:"Deathmatch", Map:"MyMap", Players:9, MaxPlayers:32, Ping:55, Locked:false, Password:"123"};
 ServerList.sortOn(["Players"],Array.NUMERIC | Array.DESCENDING);

I can't see any reason why we wouldn't be able to sort arrays and be able to determine the sort type. There's only a small handful of types available anyway. If it's a string, it's alphabetical. If it's a numerical value, there's two options (descending or ascending) and that's almost all that's ever needed. A simple dropdown in the blueprint node would only need 4 entries. (name of the struct object, alphabetical, ascending and descending).

I'm in blueprints trying to create a struct of objects and their distances from the player. I simply want to sort the array of those structs by the distances to quickly and easily put the closest one at index 0. Taco's method seems absurdly convoluted in comparison to what I can do in Flash.

avatar image RumbleMonk Aug 03 '14 at 04:12 PM

Lovely, thanks a lot for posting this. It does seem this causes an error however during getting the index of Sorted Target Locs in the bottom left, piped into the while condition. To fix this just add a Clamp (Int) with min set to 0 after the Target Index Stepper - 1 call. As far as I can see it still works that way.

Works great for me either way, just thought I'd mention it.

avatar image Nostrildumbass Mar 04 '19 at 02:57 AM

Hate to bump something this old but thank you!!! I was getting the -1 index error and it was driving me nuts figuring out where it was. I had the right idea of what I had to do, I just didn't know where.

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

4 answers: sort voted first

Array Doc: https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/Arrays/ArrayNodes/index.html

You can use the "Filter Array" or "Remove Item" with ForEachLoop and drop them back into your array in the order of preference.

more ▼

answered Apr 21 '14 at 02:09 AM

avatar image

1.8k 131 68 110

avatar image Slavq Apr 22 '14 at 03:01 PM

I have an array of "Item" objects (my own class)... "Item" objects have "Category" enum with values like "consumable", "weapon", etc. - and I can't figure out how to sort it by Category. Maybe it's easy, but i've used to have a built-in Sort() function and doing it by hand is quite new to me :) I will be grateful for some advice or example of array sorting in Blueprint.

avatar image Tom Shannon May 12 '14 at 05:15 PM

I too could use an example of how this would work.

avatar image Zeustiak May 13 '14 at 09:59 AM


Use Filter to sort by class.

If "Item" is your parent class, and Weapon, Armor, and Consumeable are child classes, then you can filter all items, all weapons, all armor, etc.

You can also have children of the Weapon class and filter all Axes, Swords, etc.

avatar image Mistress Lillith Oct 22 '18 at 07:53 PM

Except item being stored in an inventory usually won't be actors, so the Filter function wouldn't accept an array of Inventory items

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

The low-entry extended standard library has a sort array by comparator function, which is what you'd need here.


alt text

alt text

lesort.png (44.7 kB)
howto.png (11.9 kB)
more ▼

answered Jun 30 '16 at 01:05 PM

avatar image

1.8k 66 27 90

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

Use a ForEachLoop node.

more ▼

answered Apr 20 '14 at 10:05 PM

avatar image

166 13 19 32

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

I might give you a library with a lot of array sorting things, but I can't post it right now. Maybe this afternoon or Tuesday.

EDIT: Here is the start of my extended Array library, it nowhere near finished but you should be able to get a few ideas from it. https://drive.google.com/open?id=0B-_sl3OdyWWlX19kZ0ZNVUtkODA


more ▼

answered Jul 01 '16 at 06:52 AM

avatar image

413 17 15 31

(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