# Whats the difference - Get all actors of class versus each actor registers itself

**URL:** <https://forums.unrealengine.com/t/whats-the-difference-get-all-actors-of-class-versus-each-actor-registers-itself/637204>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [August 30, 2022, 2:06pm UTC](https://forums.unrealengine.com/t/whats-the-difference-get-all-actors-of-class-versus-each-actor-registers-itself/637204 "2022-08-30T14:06:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![BIGTIMEMASTER](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bigtimemaster/32/710746_2.png) [@BIGTIMEMASTER](https://forums.unrealengine.com/u/BIGTIMEMASTER)\
**Post date:** [August 30, 2022, 2:06pm UTC](https://forums.unrealengine.com/t/whats-the-difference-get-all-actors-of-class-versus-each-actor-registers-itself/637204/1 "2022-08-30T14:06:57Z")

</div>

Can anybody explain if there is a difference between GetAllActorsOfClass (or something similar like GetActorsWithInterface/Tag/etc) and the inverse which is to have the class register each instance of itself to some manager from some event.

Either way we have to access all these memory slots, and if the actors are already present in the level they are already loaded, right? So, what’s the difference?

Additionally, is there any benefit to actors registering themselves to a database/manager based on a more generic type? e.g:

A subclass of actor (or even a subclass of a subclass) registers itself to a database, but the database is an array of just plain actors.

The database might only be needed to know how many actors there are and their location, so the subclass isn’t needed. Is something like this any performance difference?

Would a better way to find certain actors be to put out a broadcast from the manager that the actor class subscribes to, and then any actor which meets a broadcasted criteria can report itself? e.g.:

Manager puts out event dispatch which passes along a Name

each actor which subscribes to this dispatch looks at the name, and if it matches, it returns its reference to the manager

---

<div class="post-metadata">

**Author:** ![BIGTIMEMASTER](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bigtimemaster/32/710746_2.png) [@BIGTIMEMASTER](https://forums.unrealengine.com/u/BIGTIMEMASTER)\
**Post date:** [August 30, 2022, 2:18pm UTC](https://forums.unrealengine.com/t/whats-the-difference-get-all-actors-of-class-versus-each-actor-registers-itself/637204/2 "2022-08-30T14:18:54Z")

</div>

additional related questions:

If I use a GetGameMode node, is that fundamentally different than GetActorOfClass → gamemode?

In other words, is GetAllActorsOfClass more or less performant if there is only one, or only a few actors of that class?

If that was the case, then many subscribers looking for a manager must be better than one manager looking for many subscribers.

Or it is not worth even worrying about?

---

<div class="post-metadata">

**Author:** ![JoSf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JoSf](https://forums.unrealengine.com/u/JoSf)\
**Post date:** [August 30, 2022, 2:27pm UTC](https://forums.unrealengine.com/t/whats-the-difference-get-all-actors-of-class-versus-each-actor-registers-itself/637204/3 "2022-08-30T14:27:18Z")

</div>

GetAllActorsofClass goes through every actor in the level and returns an array of all actors of the corresponding class.

You ideally would want to manage your references so that you don’t need to do that.

---

<div class="post-metadata">

**Author:** ![BIGTIMEMASTER](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bigtimemaster/32/710746_2.png) [@BIGTIMEMASTER](https://forums.unrealengine.com/u/BIGTIMEMASTER)\
**Post date:** [August 30, 2022, 2:27pm UTC](https://forums.unrealengine.com/t/whats-the-difference-get-all-actors-of-class-versus-each-actor-registers-itself/637204/4 "2022-08-30T14:27:45Z")

</div>

> [@Alternative to "Get all actors from Class"?](https://forums.unrealengine.com/t/alternative-to-get-all-actors-from-class/453955/2):
>
> It IS intensive. To get round this, you need to store an array of the spawned blueprints (usually in the level BP, or the player BP, depending on what the listed BPs are), and then loop through it. You need to keep track of when to add to, or remove from, this list, but the overhead is massively less than GetActorsFromClass. The overhead of GetActorsFromClass comes from it looping through ALL the actors in the game, and returning an array where the class matched. If you create the array and mai…

this info here seems to suggest that if I register my actors at construction time (or maybe at some point during runtime if they are spawned then), that is beneficial.

But in order to find the manager I have to use get actors of class. _Unless_ the getting of the game mode/controller/other unreal default framework classes is fundamentally different than finding an actor in the level. If it is, then it seems the best solution is to register an array of actors with something like the game mode at construction time (this is how I’d store reference to actors placed at design time)

---

<div class="post-metadata">

**Author:** ![BIGTIMEMASTER](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bigtimemaster/32/710746_2.png) [@BIGTIMEMASTER](https://forums.unrealengine.com/u/BIGTIMEMASTER)\
**Post date:** [August 30, 2022, 2:28pm UTC](https://forums.unrealengine.com/t/whats-the-difference-get-all-actors-of-class-versus-each-actor-registers-itself/637204/5 "2022-08-30T14:28:07Z")

</div>

> [@JoSf](#):
>
> You ideally would want to manage your references so that you don’t need to do that.

that’s what I’m getting at here. What is an example of _how_ to manage references?

---

<div class="post-metadata">

**Author:** ![JoSf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JoSf](https://forums.unrealengine.com/u/JoSf)\
**Post date:** [August 30, 2022, 2:31pm UTC](https://forums.unrealengine.com/t/whats-the-difference-get-all-actors-of-class-versus-each-actor-registers-itself/637204/6 "2022-08-30T14:31:02Z")

</div>

Well, as an example, you can set references when you spawn the objects (expose on spawn in BP).

You shouldn’t really need any manager objects at all tbh, actors can subscribe to event dispatchers if you need to trigger some event in multiple actors. Or you could use interfaces.

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [August 30, 2022, 2:31pm UTC](https://forums.unrealengine.com/t/whats-the-difference-get-all-actors-of-class-versus-each-actor-registers-itself/637204/7 "2022-08-30T14:31:23Z")

</div>

If you want a one-many structure, then dispatchers is the way to go.
