Help sorting array of structs

Hi!

I’m trying to make a function to sort an array of structures by one of its members value (a float), from lowest to highest.
This is what I have so far:

I thought this would work fine, but it doesn’t, and I’m unable to figure out why…
Instead of returning the sorted array, the function just returns an array with the same size of the input array, but with the same item -the one with lowest value- repeated.

What am I missing?

Thank you very much in advance! :slight_smile:

This should fix it. Every time you have a node connected to the MinOfArray node, it is calling it again, and so getting a different value after the min has been removed. If you store the first value it gets each loop, you will avoid this problem:

Life-saver! Yeah, that works like a charm! ^^

Thank you SO much! I owe you a drink, haha!

It’s also worth mentioning that Rama’s Victory Plugin has a Sort node for arrays, and an option to sort by structure or object field. Works fine for me.

I made this a simply function and call it after adding something to array but it didn’t work. How should I use it?

I believe internal structure variable naming changed at some point. For example, “Health” became “Health_ab123j1h34k1341hg4” and such, so Rama’s Sort stopped finding these. It also doesn’t like spaces.
I worked around it by making my own copy of his function, taking these issues into account and treating “variable name” as “variable name prefix”. This is done in C++ though.

I try use Rama plugin sort by structure using variable name doesn’t seem be working. Do you have pic of BP show how it work?