# GetAllActorsOfClass() vs Datatables vs Arrays

**URL:** <https://forums.unrealengine.com/t/getallactorsofclass-vs-datatables-vs-arrays/484718>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [June 10, 2021, 3:16pm UTC](https://forums.unrealengine.com/t/getallactorsofclass-vs-datatables-vs-arrays/484718 "2021-06-10T15:16:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gary\_P](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gary\_P](https://forums.unrealengine.com/u/Gary_P)\
**Post date:** [June 10, 2021, 3:16pm UTC](https://forums.unrealengine.com/t/getallactorsofclass-vs-datatables-vs-arrays/484718/1 "2021-06-10T15:16:48Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [June 10, 2021, 4:22pm UTC](https://forums.unrealengine.com/t/getallactorsofclass-vs-datatables-vs-arrays/484718/2 "2021-06-10T16:22:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Gary\_P](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gary\_P](https://forums.unrealengine.com/u/Gary_P)\
**Post date:** [June 10, 2021, 5:21pm UTC](https://forums.unrealengine.com/t/getallactorsofclass-vs-datatables-vs-arrays/484718/3 "2021-06-10T17:21:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [June 11, 2021, 4:02pm UTC](https://forums.unrealengine.com/t/getallactorsofclass-vs-datatables-vs-arrays/484718/4 "2021-06-11T16:02:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ugmoe](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ugmoe](https://forums.unrealengine.com/u/ugmoe)\
**Post date:** [June 11, 2021, 9:05pm UTC](https://forums.unrealengine.com/t/getallactorsofclass-vs-datatables-vs-arrays/484718/5 "2021-06-11T21:05:33Z")

</div>

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
