Closed krojew closed 3 months ago
Are you storing an actor iterator in your own code or something? You can't do that, actor iterators are only valid in a short window of time. Yes, loading a game will re-create the world so will definitely kill you stored actor iterators among many other things.
No - in my game mode I listen to PostLoadGame
and then run a for loop with TActorIterator
on the world returned by GetWorld()
. I am expecting to find around 10 actors of given class, but I only find 2. After debugging, the rest are rejected due to being in a different world. Can't tell why those random 2 are in the same world.
Found the problem. Turns out the iterator iterates over the actors from both the previous and newly loaded world, and I simply didn't notice that. The actual error was in different place.
Possibly the previous world still exists but has yet to be garbage collected. You should probably be using the EActorIteratorFlags::OnlyActiveLevels
flag in constructing your iterator. Also note that at PostLoadGame, if you have any streaming levels, those won't have been loaded yet, only the persistent level.
Ah we crossed replies, glad you figured it out.
Seems like
TActorIterator
is not working after loading a game. When iterating actors with a given class afterPostLoadGame
fires, the iterator rejects many of the actors due to them belonging to a different world -TActorIteratorBase::operator++()
has a check which checks every actor found if its world is the same as the world its level belongs to. This check fails for some reason thus breaking iteration.