Which is faster? Arrays or DataTables

I’m building a game that has ore nodes (as actors) on a map.
My AI character needs to have a list of the locations so he can go to them and mine them. Think of a mining droid. Nothing new here.

At first, on BeginPlay, I did a get all actors by class into an array which game me a nice list of all of my nodes by node type:

Copper, (X=1370.000 Y=710.000 Z=50.000)

Copper, (X=-10.000 Y=1630.000 Z=50.000)

Copper, (X=-710.000 Y=460.000 Z=50.000)

Iron, (X=-1650.000 Y=1550.000 Z=50.000)

Iron, (X=1260.000 Y=-1650.000 Z=50.000)

Iron, (X=-1250.000 Y=-1650.000 Z=50.000)

If the player wanted the robot to mine the copper nodes, all he had to do was look up all the nodes of type Copper, pass them through a function that selects the closest node and go mine it.

Then I thought “why not eliminate the get all actors by class and put this info into a DataTable , since I know where all of the nodes are from the beginning?”

I created a DataTable like this:

—,OreType,OreLocation

1,“Copper”,"(X=1370.000 Y=710.000 Z=50.000)"

2,“Copper”,"(X=-10.000 Y=1630.000 Z=50.000)"

3,“Copper”,"(X=-710.000 Y=460.000 Z=50.000)"

4,“Iron”,"(X=-1650.000 Y=1550.000 Z=50.000)"

5,“Iron”,"(X=1260.000 Y=-1650.000 Z=50.000)"

6,“Iron”,"(X=-1250.000 Y=-1650.000 Z=50.000)"

Then found out I couldn’t get all of the Copper nodes cleanly, because I can’t do a find all records by column. So I created an array, looped through all of the rows and created an array. I think I’m back to where I started from. :slight_smile:

Is there a cleaner way to do this? (with or without blueprints, I assume I can create a C++ function)

What I want for my final result is an array of say Copper locations, or Iron locations that I can sort into distance from the droid.

Thanks ahead of time.

You could create arrays in the game instance or the robot or wherever. One for copper, one for iron and so on and add the locations hardcoded there instead of a data table. Then you don’t need to get all actors or loop through the data table. You still need to loop through the specific array to determine which is the nearest location. Hope that helps.

Thank you.
I also went down that road too. :slight_smile:
I was saving the arrays in MyGameState. It was easier to access them from there then the Level Blueprint.

Thats a good idea. Just fyi: If you need to store data across all levels, store it in the GameInstance. GameState, GameMode and all that gets resetted/reloaded when loading a new level.

Oh cool. Thanks.
I was just reading about all those. If I wanted to level’s ores to reload on level change then I’d want them in GameState or the Level BP. I didn’t know GameMode got cleared as well. (Haven’t got to that part).