Blueprint Bubblesort doesn't work correctly

Hey there.

I hope Code Review/Assistance is allowed here.

I have an array of Integers. These Integers are actually indices of an array.
These indices point indirectly onto items. These Items have an ID. The *indices *should be sorted by this ID.
For a test, I have 4 Items with the IDs

But after sorting, the indices are

I’m pretty sure my Bubblesort is ok and does not have any errors.

This is the Comparator

This is the Sort

Did I miss something? Becaus I feel pretty stupid at the moment.

You didn’t attach the B node:

There’s a get max value of array function in blueprint that you can use to simplify the sorting immensely. Here’s an example setup (not mine).

Obviously you’d need to tweak this to build the correct array, but you get the idea.

It is attached, it’s just a reroute node.

I’m not sorting the int array itself. so this doesn’t help me.

The content of this array are actually Indices of an array.

IndexArray->Int->Index of Item in the Inventory -> Index -> Item -> ID

I want to sort the Items by ID.

As long as you perform the operation on the correct array, or set of arrays you can still do that easily.

Check out this picture:


“Raw Distance” is an array of floats which corresponds to the array “Chunks”.

After I loop through this, ChunkIDByDist will be sorted in ascending order by the values in “Raw Distance”.

I guess you misunderstand me. I don’t have an array of ints or something like that.

I want to sort the Indices (left) by the ID (green)

Looks like this could potentially try to access an index greater than the length of the array. The first setarrayelem has an opportunity to set Item to array.get(arraylength), which is the element after the last element in the array. I tried implementing these nodes and blueprint would crash silently.

By comparing A with B, but swapping A with A+1 (which could be completely different index from B), I’m not sure the result is actually getting sorted.

And then you need to run the bubble sort repeatedly, because one pass of bubble sort won’t be enough.