Game Mode doesn't get carried over when seamless travel

When I use the console command servertravel Map both the server and the client are transferred to the transition map, and from there to the destination map, but according to the documentation, the Game Mode should persist automatically, but when the destination map is loaded, then a new Game Mode is created, and so both BeginPlay and Construction Script events are called again, and also because it is a new object it’s variables are back to the default values.

In case that documentation is kinda misleading, what should I do so that the game mode will get carried over to the new map? Can you do it for the Game State and all the Player State as well?

Have you tried to set the Game Mode to be the same for both maps?

I did 3 test:

  1. Destination map has the Game Mode set to None:
  • Result: When the destination map is loaded the game mode from the map before it is used and BeginPlay is triggered and also the values are set to default;
  1. Destination map has the Game Mode set to a different one then the map before it:
  • Result: When the destination map is loaded the game mode set on that map is used and not the one from the map before it (same, BeginPlay is called, and values are set to default, but here it couldn’t have had new values as it is the first time it is used);
  1. Destination map has the Game Mode set the same as the map before it:
  • Result: Same as 1, when the destination map is loaded the game mode from the map before it is used and BeginPlay is triggered and also the values are set to default.

I could add in Game Mode’s event BeginPlay to instruct it to read the values of the old one, by setting those inside the Game Instance just before calling the command servertravel, but if the game mode shouldn’t change on map transition, then I’d rather find the cause of the “reset”. //Edit: Or set them inside the game instance when EndPlay is called from the game mode.

//Edit:
Or is it that by “persist automatically”, they don’t actually mean that it will keep the values inside of it, but rather the case 1, where if I set on that map GameMode to none, it will use the same type of GameMode, rather then it will use the exact same one, with all it’s values?
From my testing the only ones that kept even their values were the Player Controller. In the lobby I changed the values for a variable (one that keeps track of the class they are using for the pawn) for both the client and the server, with different ones, and when the new map was loaded, then they kept those values.

That’s weird. In my case it works the other way around where the game mode persists but I’d actually like to have my new Game Mode associated with the target map being launched.

First I must mention that I’m using Blueprints and not C++. Also when I looked over the documentation I did saw this where it does say that GameMode should persist but in my case it doesn’t (more information bellow), and I’m using the command servertravel Map and not the blueprint Server Travel:

When I’m using the command servertravel Map and the new map gets loaded, a new GameMode is made, but if it is right or not, this is I also what I want to happen.

What I’m doing is this:

  1. I have a parent actor for GameMode, GameState, PlayerController, PlayerState which contains some general stuff for all the maps, and from that I’m creating a children for each of the map that contain functions and variables related only to that map
  2. When the game starts I have a map with the intro stuff and when that is done I’m calling Open Level (by Object Reference) for “Main menu” and in it’s options I only added ?listen
  3. When I want to change the map for everyone, I call Execute Console Command with the content being servertravel MapName
  4. For creating a session I’m using the plugin AdvancedSessions (without the Steam part as I don’t need it) and call from it Create Advanced Session, and for joining a session I’m using the same plugin with Find Sessions Advanced then the core Join Session

I did some tests and every time the new map was loaded a new GameMode was created even if I used the same object for all the maps, and because a new GameMode is being made then the rest also gets created again (GameState, PlayerControllers, PlayerState). And that was the reason I ended up using the parent/children method now for each of the maps, as this way I can organize those actors a lot better, and not be filled with stuff that some maps won’t use, and find what I want a lot faster.

One thing I want to mentions is to be careful when the new map is loaded, as widgets already visible on the screen won’t go away, but that isn’t a problem. When “Start” button is pressed I’m calling Remove All Widgets then I’m creating a new widget with the loading message, and on the new map when the time is right and everything is ran, I’m calling again Remove All Widgets and create what widgets I need for the new map.

Your setup is pretty similar to mine I guess. I am also using Blueprints only and yesterday I finally managed to make the target GameMode kick in when I execute servertravel via console. I simply attach my desired gameMode to the servertravel’s option string and my Menu GameMode gets created when I go back to the lobby.

Hmm, I don’t need to do that. When I’m changing the map from main menu I’m calling:

image

And from the map when I want to go back to main menu:

image

And all the players are sent to the new map be it from main menu to an “action map” or from that back to main menu.

If I’m not closing the ability for clients to find the server, then they can join when the host is in main menu (they will load MainMenu map), or if the host traveled from main menu to a new map (they will load that new map when joining), or if the host traveled from main menu to a new map, and then back to main menu (they will load MainMenu map).

In short, if I’m not closing the ability to find the server, they will be able to join and they will load whatever map the host is on at that time and that map GameState, PlayerController, PlayerState are being crated and replicated to the clients.

Well if I do it like you, my host will also drag all connected player along with him. The issue I had was more related to the GameMode. on the LobbyMenu I have a GameMode “Menu” onmy actual playable map I have a Gamemode “Match”. When I return from the Match map to the Lobby with the simplest servertravel, the server, all my connected clients and their possessed pawns get loaded into the lobby. And on top of that, whilst being on the lobby map I don’t have my Menu gameMode beign active, but still running the Match GameMode. That’s why I attached the GameMode overwrite to the server travel string