Keeping Actors Between Levels

At the moment there are few ways to keep actors alive between levels, and we are discussing a new idea to help this going forward.

For now you’ll want to use “seamless travel”, which keeps network connections alive between server/clients while loading the next map/level. On the AGameMode there is a boolean “bUseSeamlessTravel”, that will make sure calls to ServerTravel will go a different path when loading maps. Seamless travel basically loads a small map as a transition so that it can garbage collect the previous map. It then continues to load the destination map afterward. This way, we can prevent a memory high watermark and possible out of memory conditions on limited memory platforms (ie console). You’ll need to specify a small transition map in DefaultEngine.ini

[/Script/EngineSettings.GameMapsSettings]
TransitionMap=/Game/Maps/SmallTransitionMap

With seamless travel, there is a call GetSeamlessTravelActorList which will allow you to add actors to an array of AActors to preserve between levels. It guarantees they won’t garbage collected and will be “renamed” into the next level. I don’t know why it’s called Rename, but basically it moves the AActor into the next UWorld and in fact the name does change (the FName gets its _ number incremented).

Now, not many things get preserved across travel, the point being that whatever object had a pointer to the object you’re preserving is probably getting garbage collected, so the direct reference to your AActor is going to be lost. APlayerController typically survives longer than other AActors (unless the class of controller is changing). You can always do a TActorIterator<ClassToSave> to find the object(s) again and reestablish the linkage. There are a couple of places at this transition where you still have the old AGameMode and AGameState and could theoretically hand off a pointer, but I just looked and it isn’t well exposed in an overload fashion (ie you’d have to modify the engine code a little).

The GetSeamlessTravelActorList function will be called twice, once when the transition map is reached, and again when the destination map is reached.

Hope this helps, let me know any addition questions you have as you work through this.

1 Like