Changing GameMode on Maps (ServerTravel)

Looking at the documentation for GameMode it seems there are only 4 ways of setting a GameMode in your maps.

  • Set it in defaults and it sets it to all maps which have no gamemode override
  • Set it in world settings gamemode override
  • Pass the game mode to the game on start
  • Set a map prefix alias that will load a specific game mode when the map with that prefix is loaded

Does this mean that we cannot have one map be used with multiple game modes?

Let’s assume we have 2 maps (Map A and Map B) and 2 GameModes (GM_A and GM_B). Map A and B have their default override to None, meaning they should be inheriting the default GameMode. I want to override the default GameMode to be either GM_A or GM_B at the push of a button. This would work in a single player setting by modifying the options the URL is given on “OpenLevel”. However … what if I want to ServerTravel and take multiple players along to that specific GM_A or GM_B. From the documentation it sounds like I need to make Map A_GM_A and Map A_GM_B (essentially creating a copy of Map A with the only purpose to be changing the override game mode).

Is there no other way? It seems … wrong …

Any thoughts on the matter?

Hello Justin!

Did you find solution?

Nope, still waiting for someone nudges epic to get back to me about this :slight_smile:

I’m going to try bumping this every 4-5 days, hopefully it attracts some eyeballs :slight_smile:

Any new info?

Still looking for feedback on this.

I can’t possibly be alone in wanting to find a solution to this :stuck_out_tongue:

Was struggling with this for quite some time.

Seems like the options to change game mode does work for ServerTravel after some long reading of the source code for the engine. However only if you do so via C++, as the console commands goes through UEngine::HandleServerTravelCommand which seems to not have the code to parse out the options. (I haven’t built the engine from source code so I haven’t tried editing some code out of that to verify my assumption)

To test using ServerTravel with a different game mode in C++ i did the following in Unreal Engine 4.8.2

1: I made a test project with the template C++ ThirdPerson with project name “GameModeTravel”

2: Built the project in Visual Studios so I could do the following in the Unreal Engine 4 Editor

3: Added a Action Mapping in Project Settings->Input named “Travel” to the F key

4: Added a function/method AGameModeTravelCharacter::TestTravel in GameModeTravelCharacter.cpp

5: Added void TestTravel(); in GameModeTravelCharacter.h

6: Added InputComponent->BindAction("Travel", IE_Pressed, this, &AGameModeTravelCharacter::TestTravel);

7: In the TestTravel function/method I implemented this

void AGameModeTravelCharacter::TestTravel()
{
	UE_LOG(LogTemp, Warning, TEXT("Test Travel"));
	GetWorld()->ServerTravel(TEXT("/Game/ThirdPerson/Maps/TestMap?game=/Game/ThirdPerson/OtherGameMode.OtherGameMode_C?listen"));
}

8: Compiled/Built the project.

9: Added a GameMode blueprint with the name “OtherGameMode” located in Content/ThirdPerson

10: Created a New Level and saved it as TestMap and put it at Content/ThirdPerson/Maps

11: In OtherGameMode blueprint in the EventGraph’s EventBeginPlay I added a node to print a string saying “OTHER GAME MODE!”

12: Saved, Built and Compiled Everything to make sure (not sure if necessary)

13: Packaged Game for Windows 64 bit

14: Open one instance of the packaged game

15: Open console in package game and type in “open ThirdExampleMap?listen”

16: Open second instance of the packaged game

17: Open console in package game and type in “open 127.0.0.1”

18: In first instance of the package game, I press F.

19: Watch as the second instance character disappears (due to lack of seamless travel)

19: Loads in the other map, prints out OTHER GAME MODE!, and see the second instance ball being stuck on the center of the floor due to the origin 0,0,0 position.

To test seamless travel just change the TestTravel function/method to the following

void AGameModeTravelCharacter::TestTravel()
{
	UE_LOG(LogTemp, Warning, TEXT("Test Travel"));
	GetWorld()->GetAuthGameMode()->bUseSeamlessTravel = true;
	GetWorld()->ServerTravel(TEXT("/Game/ThirdPerson/Maps/TestMap?game=/Game/ThirdPerson/OtherGameMode.OtherGameMode_C?listen"));
}

Hopefully this helps anyone who might want to change the game mode with server travel.

EDIT: So I was googling for this issue after a year long of not touching UE4 and found my own answer. Here’s a working project that is able to change game mode on seamless server travel. GitHub - Tinyted/June13UE4: Learning Project for UE4 (As of commit: be8806e364c1512c2f1c3145b604a030e53c4de0)

Any chance to achieve this with blueprints only?