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 to sort an array alphabetically?

I have an inventory system in the game that I'm creating, and it works rather well. For sake of organization, I'd like to know how I'd be able to better organize it, as items are simply added to an array and displayed in the order that they're picked up. Each actor has different properties such as an item name, weight, if it can be eaten or not, etc.

What I'd like to know, is how I can pull each of the actors from the array, get their name, organize them alphabetically, and then put the actors back in the array with that new order, A through Z.

Any assistance is greatly appreciated! Thank you!

Product Version: UE 4.9
more ▼

asked Mar 10 '16 at 04:30 PM in Blueprint Scripting

avatar image

29 12 10 12

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

3 answers: sort voted first

currently, blueprint doesn't have anything for sorting arrays, and sorting alphabetically would be expensive and difficult in blueprints. i think the easiest way to solve your specific problem, is to put all of your game's items in a spreadsheet, and sort that spreadsheet in Excel or Open Office. one of the columns of the spreadsheet could be a Priority integer, which can start at 0 and increment for each row. then, in your game, you can sort your inventory by Priority, instead of ripping apart strings to compare letters.

then you can loop through your items, ripping out the Priority value, and putting it into an array of Ints.

use MinOfIntArray or MaxOfIntArray to create a new temporary array of ints, as well as a new temporary array of your Item structs. every time you copy and delete an entry from the list of ints, do the same to the corresponding element in the list of structs.

https://answers.unrealengine.com/questions/176672/sorting-float-array-numerically.html https://en.wikipedia.org/wiki/Sorting_algorithm

sorting strings and ints should be a built in engine feature in my opinion, and i have no idea why it doesn't already exist. it would be nice if blueprint allowed you to override comparison operators, but you need to use C++ for that. currently, strings can be compared for equality, but there is no greater than or less than operators, and there is no MaxOfStringArray/MinOfStringArray, which would also help.

more ▼

answered Mar 10 '16 at 05:41 PM

avatar image

9.6k 320 205 449

avatar image PFG_Icarus Mar 10 '16 at 09:04 PM

Thank you for the prompt answer. I'll have to sort the items alphabetically and then look into using this solution.

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

I know, this is an old post but I find a better solution in blueprint and I post it here if someone need a better solution : you can use the node "Get Character as Number" to connvert, like the node say, a character in a number that you can compare and sort.

more ▼

answered Sep 01 '17 at 10:37 AM

avatar image

88 2 4 4

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

I found myself problem like yours and found a solution. You can use implementation from Low Entry Extended Standart Library here Create a comparator function and attach it. Here's the blueprint of my implementation:

alt text alt text

sort.png (56.9 kB)
more ▼

answered Jun 07 '18 at 10:46 AM

avatar image

1 2

(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