I know this is blueprint part but might be useful as this came up when I was searching, I ran into this in c++ here’s what I found.
Internally in data table it’s just a TMap which the documentation says isn’t guaranteed to return in a specific order if you just iterate through it.
However this obviously happens in the editor as first screen shot shows in this thread and it’s predictable.
I found this in the editor source code so it looks like you could just iterate it and say the order found is the index but I wouldn’t trust it in case it changed in the future.
// Our maps are ordered which is why we can get away with this
// If we ever change our map implementation, we'll need to preserve this order information in a separate array and
// make sure that order dependent code (such as exporting and the data table viewer) use that when dealing with rows
// This may also require making RowMap private and fixing up all the existing code that references it directly
const int32 CurrentRowIndex = OrderedRowNames.IndexOfByKey(RowName);
if (CurrentRowIndex == INDEX_NONE)
So you can use that as a template, below is an example where I’ve done it to get an ordered copy of a data table into a TArray in the order it is in the editor, I’ve deliberately taken a copy of the struct the row is based on on purpose rather than pointers before I get told that it’s a bit hacky but works fine for a one off initial loading for small datasets.
Would be pretty easy to write a blueprint bit of code exposing that to get a TArray back in same order as the DataTable was just not something you would want to do over and over and be aware that the behaviour might change in future versions of unreal.
if (InventoryDataTable != nullptr)
//generates an ordered array this is what's used in the editor display
if (orderedRowNames.Num() > NumberOfSlots)
NumberOfSlots = orderedRowNames.Num();
for (int32 i = 0; i != orderedRowNames.Num(); ++i)
//get copy of it out of the data table won't be using data table again
InventoryItems* = *(InventoryDataTable->FindRow<FInventoryItemRow>(orderedRowNames*, contextString));