I was updating my code to use the new SortAttribute so I can sort an array of complex types by the vector member they have.
On normal array<vector> the ordering returned by Sort is exactly what I would like and I was expecting the SortAttribute to do the same.
However, as the code below shows, the ordering does not behave the same when sorting my complex type. The ordering does not appear to make any sense as well.
Perhaps vector is currently not a supported type in SortAttribute and thus the sort logic falls back to sort the array by pointer arithmetic or the wrappers instead? I can not explain how an ordering of 3 0 1 could otherwise happen. No matter if ASC or DESC it should be impossible in any kind of sorting operation.
class EDF_SortWrapper { [SortAttribute()] vector m_SortValue; //------------------------------------------------------------------------------------------------ void EDF_SortWrapper(vector sortValue) { m_SortValue = sortValue; } } //------------------------------------------------------------------------------------------------ static void Reproduce() { array<ref EDF_SortWrapper> data = { new EDF_SortWrapper("1 9 1"), new EDF_SortWrapper("1 2 1"), new EDF_SortWrapper("0 9 9"), new EDF_SortWrapper("3 0 0"), }; data.Sort(false); foreach (auto entry : data) { Print(entry.m_SortValue); } array<vector> data2 = {"1 9 1", "1 2 1", "0 9 9", "3 0 0"}; data2.Sort(false); data2.Debug(); }
SCRIPT : vector m_SortValue = <3.000000,0.000000,0.000000>
SCRIPT : vector m_SortValue = <0.000000,9.000000,9.000000>
SCRIPT : vector m_SortValue = <1.000000,2.000000,1.000000>
SCRIPT : vector m_SortValue = <1.000000,9.000000,1.000000>
SCRIPT : Array count: 4
SCRIPT : [0] => <0.000000,9.000000,9.000000>
SCRIPT : [1] => <1.000000,2.000000,1.000000>
SCRIPT : [2] => <1.000000,9.000000,1.000000>
SCRIPT : [3] => <3.000000,0.000000,0.000000>