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.
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:
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 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.