Loading different map in-game

The game I’m working on is mission based and so we have distinct maps - essentially one map per mission. That means that to progress through the game, we have to unload the current map and load a new one. Streaming doesn’t seem like it serves our needs.

I am able to load a new map via UEngine::PrepareMapChange and UEngine::CommitMapChange - but what I’m seeing is that it loads the new map into the current world - so all the actors from the old map are still there along with all of the actors from the new map.

It seems like I could just remove all of the actors from the old world before loading the new map - but is that the intended usage? Or am I doing something completely wrong? I can’t find any documentation on loading different maps that isn’t to do with streaming - so the current functionality is gleaned from the headers.

I’m curious about this, too. We need to figure out the RIGHT way to load and unload maps.

I’m not in a situation where I can check it out, but UGameplayStatics::OpenLevel might be what you’re looking for

PrepareMapChange and CommitMapChange are meant to be used for a game where you keep things in memory throughout, such as a long linear single player game.

For what you’re talking about I recommend using UWorld::ServerTravel. It’s fairly similar to OpenLevel but will handle having clients come along with you. This one will tear down everything and bring it back up again. It’s currently a bit tricky to get player state to come along with you, but you can use some of the methods I mention in this question:

Thanks for your response! It actually does work - but I have to select the answer by Ben because it will work in a multiplayer environment.

I feel sad about this because your beard is awesome and better than mine - and I don’t know whether Ben has a beard. Us beardies have to stick together!

Thanks Ben! This is now what I’m using.

For anybody who may have searched for this, the URL you need to pass in to ServerTravel is going to be:

/Game/Maps/map

where “map” is the filename (without extension!) of the map you want to load.

No worries! His answer actually helps me out too (despite his beard ambiguity)

is there anyway to get a list of all *.umap file’s address inside of my content folder.
basically my problem is that i have my map’s in different location.not in a specific folder.
and do not want to hard code all umap file’s address

I would suggest that you’re making it much harder for yourself if you don’t keep all of your maps in the same content directory (normally Content/Maps which translates in-game to /Game/Maps).

That said, take a look at FPackageName::FindPackagesInDirectory because that is almost the code you need. :slight_smile:

“FPackageName::FindPackagesInDirectory”
ooh.that was fantastic.
after examining it’s defination i got my one.

IFileManager::Get().FindFilesRecursive(	OutPackages, *RootDir,FileExtension	, true, false);

that did the trick.

ou’re making it much harder for
yourself if you don’t keep all of your
maps
from now,“FindFilesRecursive” will do that part. I do not have to keep track map files myself.
Thank your for your help

For future reference, here’s my post about using PrepareMapChange / CommitMapChange:

As I see it, anything not being referenced after CommitMapChange has been called will be deleted by the garbage collector. Not need to explicitly clean it up.