GetAllActorsOfClass() vs Datatables vs Arrays

I’m building a level that has different types of resources; trees, ores, etc. yup, same thing different day.

Except that I didn’t want to use GetAllActorsOfClass() every time I wanted my mining bot to search for local ore sources.
So I created a function that could be run as a utility by me (not in game) to read all of the resources, and add them to a DataTable. Next I was reading that using multiple DataTables is better then one with a lot of rows.

The reason for the dataTables is when the the player instructs the mining bot to go get me all of the copper, the bot reads the DataTable, copies all of the copper nodes to an Array, then gets the closest copper node out of the array.

After the bot mines the copper node, it destroys the actor and removes the element from the array.
Or It hides the actor, removes the element from the array, and sets an internal timer so the ore can respawn.

I also looked at Data Assets too.

Am I going about this correctly? Should I have 1 huge dataTable that lists all of my resources? It could get big really quick.
Or just at the beginning of the game, do the GetAllActorsOfClass(), copy the Vector Locations to the array(s) and be done with it.
I assume I’m not the first guy to do this. :slight_smile:

Hello! GetAllActorsOfClass is using TActorIterator, that is using just arrays. Another option - take a look at ForEachObjectOfClass and ForEachObjectOfClasses global methods from UObjectHash.h - here fast hash bucket implementation is used, so it can be more effective.

Thank you.
I assume I’d have to do this in a C++ to Blueprint function? I forgot to mention I’m using Blueprints.

Ok, I will check BPs, because prev comment is about C++…

you could also attach a SphereCollision volume to your character and use the GetOverlappingActors node with the target being your SphereCollison

This would give you only the actors that are with the radius of your character

For your resource actors, you would have to enable “Generate overlap events” in the details panel. And make sure you have the correct collison channels set to Overlap instead of Block

Then, if your mining bot was not in radius of any resources you could have him roam around looking or something like that