x

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"

Get All Actors Of Class with Level Streaming broken after update to 4.9

In 4.8.3 it worked perfectly. Level streamed, actors placed, event beginplay starts. Now beginplay starts before an actors from the streamed level presents at the scene and Get All Actors Of Class returns an empty array.

It works fine with the single level or with Always Loaded method but once same levels switched to the blueprint streaming methot it stops working. Though little delay helps but thats just silly.

Steps to reproduce:

1 - create blank project with a persistent and streamed levels (blueprint method).

2 - create new actor bp with code (also tried placing it at the beginplay of the streamed level bp, same result) and place it at the streamed level: alt text

2 - Stream level at the persistent level bp:

alt text

3 - Result:

alt text

Product Version: UE 4.9
Tags:
stream1.png (73.7 kB)
stream2.png (30.1 kB)
stream3.png (9.5 kB)
more ▼

asked Sep 01 '15 at 09:14 AM in Bug Reports

avatar image

Arida
236 8 8 14

avatar image qimmer Sep 02 '15 at 08:16 AM

I have the exact same issue! Worked fine in 4.8.2, but in 4.9, GetAllActorsOfClass doesn't find anything. It seems it is related to, that the outer object is now the persistent level and not the streamed level. If you in C++ use GetObjectsOfClass(), you retrieve them all.

This seems to only be a problem in BeginPlay(). Maybe BeginPlay is called prior to the streamed level has finished loading?

avatar image mills Sep 02 '15 at 02:19 PM

I'm having the exact same issue as well and your description is spot on. It works fine in the single level, but when streamed from another level it's broken, but worked fine in 4.8. The only difference for me is I'm calling GetAllActorsOfClass in C++ during BeginPlay for certain actors (instead of the blueprint approach), but the result is the same.

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

1 answer: sort voted first

Hi Arida,

Thanks for the report! I was able to reproduce this in 4.9.0 as well as our internal builds, and I've entered a bug report for the issue (UE-20736). I'll post here when I see any update.

I spoke with the developers about it, and the problem is not that Event Begin Play is being fired before the streaming level is loaded. Instead, the problem is likely a timing issue with Get All Actors of Class. I'll let you know if I find out more. For now, using the delay is your best bet.

more ▼

answered Sep 03 '15 at 06:12 PM

avatar image tardygrade Sep 12 '15 at 08:20 AM

For me GetAllActorsOfClass is completely broken regardless of timing (For test purposes I added it to gamemode's tick, and then entered there with a debugger long after the streamed level was loaded. The actor from the streamed level was not there). The streamed level does have the actors as I get their beginplay events just fine. Also iterator seems to be broken as well - only returns actors from the peristent level. I posted this here, before I found this thread: https://answers.unrealengine.com/questions/301099/has-something-changed-with-getallactors-in-49.html

avatar image tardygrade Sep 12 '15 at 08:32 AM

And for completeness sake, here's the test code I added in my GameMode::Tick event :

auto loadedlevels = GetWorld()->GetLevels(); TArray actorstest; for (auto level : loadedlevels) { for (auto actor : level->Actors) { actorstest.Add(actor); } } TArray actorstest2; for (TActorIterator ActorItr(GetWorld()); ActorItr; ++ActorItr) { actorstest2.Add(*ActorItr); }

So, I'll wait for about 10 seconds after I load the level. Then I'll go here and add a breakpoint. The result - actorstest : 34 actors, actorstest2: 31 actors.

avatar image tardygrade Sep 12 '15 at 08:34 AM

And for completeness sake, here's the test code I added in my GameMode::Tick event :

 auto loadedlevels = GetWorld()->GetLevels();
     TArray<AActor*> actorstest;
     for (auto level : loadedlevels)
     {
         for (auto actor : level->Actors)
         {
             actorstest.Add(actor);
         }
     }
     TArray<AActor*> actorstest2;
     for (TActorIterator<AActor> ActorItr(GetWorld()); ActorItr; ++ActorItr)
     {
         actorstest2.Add(*ActorItr);
     }

So, I'll wait for about 10 seconds after I load the level. Then I'll go here and add a breakpoint. The result - actorstest : 34 actors, actorstest2: 31 actors.

avatar image tardygrade Sep 12 '15 at 09:09 AM

Nevermind my previous posts. That was my screwup. So yeah, it is the delay issue. In my beginplay of level if I put: TArray actorstest; UGameplayStatics::GetAllActorsOfClass(GetWorld(), AMyCharacter::StaticClass(), actorstest); It will return empty. But if I put the same in gamemode's Tick event eventually it will start returning 1 (after a few update cycles)

avatar image sgehrman Sep 22 '15 at 09:49 AM

Could you make this a priority? Just tested the master branch tonight and the bug still exists.

avatar image Ben Halliday STAFF Sep 22 '15 at 01:09 PM

All we can do is bump the community interest level on it, which I have done. Is there a reason the delay workaround doesn't work for you in the meantime?

avatar image Tam Armstrong Sep 30 '15 at 12:35 AM

This bug looks like it cropped up when the Actor Iterator was refactored. The previous actor iterator made use of a Level Filter Class, but notice that the templated Actor Iterator doesn't specify a Level Filter. That means it was using the Default Level Filter:

 template<typename FILTER_CLASS,typename LEVEL_FILTER_CLASS = FDefaultLevelFilter>
 class TActorIteratorBase :
     public FActorIteratorBase

 template <typename ActorType>
 class TActorIterator : 
     public TActorIteratorBase< FActorFilter >

Which wasn't culling the iteration results based on whether the level was visible:

 struct FDefaultLevelFilter
 {
     bool CanIterateLevel(ULevel* Level) const
     {
         return true;
     }
 };

However now the iterator itself implements the result culling and both Actor Iterator implementations perform the culling:

 template <typename ActorType>
 class TActorIterator : public TActorIteratorBase<TActorIterator<ActorType>>
 {

 static bool CanIterateLevel(ULevel* Level)
 {
     return Level->bIsVisible;
 }

This is a problem for this particular use case of the iterator where the streaming level calls BeginPlay() on the Actors it contains prior to marking the level visible. See:

 void UWorld::AddToWorld( ULevel* Level, const FTransform& LevelTransform )
 
     // Ultimately calls BeginPlay on the Actors somewhere up here...
 
     // We're done.
     if( bPerformedLastStep )
     {
         Level->bIsVisible = true;

The suggested fix of a Delay works around the problem by using the Actor Iterator outside of the streaming level initialization step. An easy workaround fix in any C++ code with this problem is to implement a custom actor iterator with the previous behavior.

avatar image tardygrade Dec 04 '15 at 12:20 AM

Any update on this ? Seems to still be an issue in 4.10

avatar image Ben Halliday STAFF Dec 04 '15 at 04:45 PM

I'm sorry, no update at this time.

avatar image sloppyjava Dec 09 '15 at 04:23 PM

Has this been addressed in 4.10.1?

avatar image Ben Halliday STAFF Dec 09 '15 at 04:25 PM

No, and we do not expect it to be fixed for any hotfixes. As mentioned above, there has been no update on the report itself, including a fix, but we will post here once there is. Thank you.

avatar image rent treznor Feb 01 '19 at 08:15 AM

Four years later. Any fix?

(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