Is there a better way to loop through all elements of a datatable?
So after much experimentation, I found that I was unable to import a datatable from a CSV file and then use Blueprints to loop through all the elements that were read in through the table. This is because UnrealEngine provides the useful GetDataTableRow node, but I found that I was completely unable to use a ForEach loop node to get all the rows from the table. I WAS able to create a regular ForLoop node and iterate, but only if I hard coded in the number of elements into the loop, since currently there seems to be no way to query the DataTable for its total number of rows?.
I searched the forums for a while and found no information about how to do this.
After considering my dilemma for a bit, I invented the following way to successfully read in all rows of any DataTable read in from a CSV datatable node. However, it would be nice if say, there was a DataTable node called: GetNumDataTableRows that would return the total number of elements in the table - but that doesn't exist afaik.
Anyway, I show how to create your own WhileLoop which can easily get the results you need to read in all rows of the DataTable. I hope this helps anyone else out there who ran into the same issue as me. And by all means, if someone has a better way, please post! :P
The ForEach node operates on arrays. DataTables are maps, not arrays, so that node won't immediately work there.
answered Jan 19 '15 at 05:04 PM
Hi First, thanks for your post. I was running into a similar problem with needing to read an element from every row.
I have made a modification to your graph for my own use. Instead of requiring the row name to be a variation of an INT, I have added a new column in my CSV labelled "Next row". This is the name of the row following it. This is read from the row in each iteration and updates the row name to read next. The final one is filled with END. A String!= for the while loop check is done with each row.
I have also set the while loop "row not found" to break the loop; incase I forget to add the END when updating the table.
answered Feb 13 '15 at 12:18 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here