Download

C++ Snippet - Sorting Arrays of UObjects or UStructs by arbitrary variables

I adapted this code from here so that I could use it to sort UStructs as well as UObjects.

There’s no blueprint implementation in my version but you can adapt one from the original article easily enough.

The main changes are that the UObject predicate requires you define a Class that both terms in the predicate must be children of. I also fixed the sorting by String/Name/Text as they were sorting in the wrong directions.

The UStruct version takes a struct as a template variable and can only be used to sort arrays of that struct type, this was the only way I knew how to get it to work.

You can’t sort the arrays by structs but you can sort by almost any other property type.

I recently added a Generic Sort Array node to Rama’s Victory plugin.
It also handles objects and structs, though I didn’t realise there was a wiki entry for one already.
Would have saved me a bit of time :stuck_out_tongue:

Thanks for this.