Sorting an array based of a struct value

I saw a post about it and try to implement in my game but it didn’t work. What am I doing wrong?

1 Like

Hi w0hoho, I’ve attached a working example of reordering a struct based on content values.

It’s not necessarily the best way of doing it. The last node used needs to be a number appropriate to the scale of the values you’re using. If your max value is 1000 then this needs to be something higher than that. (it’s only used so that this array element is never chosen by “Min int of array”)

Hope this helps

Thank you for your answer. I made it on my project but then I realized, it is not about the array. I add those cards to a scrollbox as child. They are not added by the cards array. I don’t know how to sort the scrollbox.

It is almost always better to perform array manipulations in C++ rather than in Blueprints both in terms of performance and convenience so you might want to try sorting in C++.

As for your problem with scrollbox, you would need to retriveve the values of the cards from it and store them in the array, then sort the array as you do, clear the scrollbox and fill it with sorted values again.

Hope it helps

I get values of the card but how do I connect the values with that scrollbox? Let’s say I make an array of card values and then clear the scrollbox. Then, how do I add them based on that value?

You mentioned that you add the cards to a scrollbox as children. When you need to sort them, you retrieve the children’s value from the scrollbox, sort the values, clear the scrollbox and populate it again. Is it what you do not understand? Otherwise I did not quite get what is the problem.

Yea that’s it. I get the value now but array is not sorted. I tried so many ways.

Does anyone know any other way?

I figured it out. After the ‘while completed’, I clear the first array, then set the new array to the first array.

1 Like