Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Cost of Get All Actors of Class

Calling this once per blueprint widget (UMG) tick to grab players and bots (ShooterCharacter). Bad idea? Is this a brute force search or is this query optimized in someway (spatial partition, actor pools)?

Product Version: Not Selected
more ▼

asked Jan 07 '15 at 07:21 AM in Blueprint Scripting

avatar image

58 8 8 17

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

FYI - For future users, I thought it would be important to note that GetAllActorsOfClass DOES NOT iterate over all actors. It only iterates overe a hash of all actors of that class...

TActorIteratorBase is a templated class and queries a class-specific hash.

See http://www.casualdistractiongames.com/single-post/2016/09/15/Inside-UE-Source-FUObjectHashTables-the-magic-behind-GetAllActorsWith

more ▼

answered Nov 07 '17 at 12:38 AM

avatar image

349 7 12 22

avatar image Yatima1460 Nov 16 '17 at 12:08 AM

So GetAllActorsOfClass is O(N) with N the number of Actors of the specified class in the current level?

avatar image sidno Nov 17 '17 at 06:32 PM

The hash table used is likely similar to an unordered_map. So, it depends on the hash function used to distribute the elements into buckets, where best case would be O(1) and worst case (if all elements end up in the same bucket due to a bad hash function) would be O(N). The answer in this link explains it pretty well:


Assuming UE4 uses a well tested hash function for these per class Actor hash tables, I'd assume you'd normally have the best case of O(1).

avatar image Yatima1460 Nov 17 '17 at 08:06 PM

What I'm pointing out is that it needs to copy the Actors references to a TArray anyway (from the map to return for the Blueprint system) so it should be O(N) always, with N being the Actors of the class selected

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Just a thought, but why not have players added to an array on join, and removed on disconnect. Then do the same for bots on spawn/destroyed. That way, you only have to interate through the list for whatever you are trying to do, not build the list and THEN do whatever you have to do. If you are really worried about missing something, set up a timer (like once a second) that polls the Get All Actors of Type and checks the arrays.

more ▼

answered Jan 08 '15 at 01:42 PM

avatar image

704 44 28 68

avatar image sidno Jan 09 '15 at 02:00 AM

Yes, that would be great! So, how can you go about doing that? Are there join/spawn/exit events I can listen for in a blueprint? Not seeing anything obvious yet. Maybe something in code I can expose?

avatar image RAVaught Jan 15 '15 at 10:34 AM

Hrmm, not sure on that one. I was going to say use the begin play event, but that might not work well with respawning.

avatar image Zoubi May 04 '15 at 12:50 PM

There are Login and Logout functions in AGameMode which could be used in C++

But in BP, I don't know :/

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

GetAllActorsOfClass() is a brute-force search so it does not scale well and can be slow. Of course if you do not have a lot of actors spawned it might not be a problem.

I have not seen any profiling markers is that function so it is hard to check how much time is really spend getting all the actors.


more ▼

answered May 04 '15 at 12:46 PM

avatar image

294 15 136 34

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question