First of all, I know the [different possibilities to set the GameMode for a game/map][1] ([Link2][2]). Futhermore, I did some research on this topic, found some similar threads/questions (most, however, on earlier engine versions) and also [this solution using C++][3].
Anyway, since this solution is from 3 engine-versions ago, I still hope for a BP-based solution for this issue. We are creating a game with currently 4 different GameModes (all based on one parent class) and levels which are set up to work with all GameModes. To add each level 4 times would waste resources and to put the logic for all game modes into one BP seems to be anything but best practise.
To change maps, our prototype uses the ServerTravel command, as it [seems to be the best/only option][5]. If we could use Open Level instead, this would allow us to [change the GameMode with the passed options][6]…
So, is there currently a possibility to to use different GameModes for one level in a Multiplayer Game with Blueprints?
void AGameMode::MyServerTravel(FString mapName, FString gameMode, bool bAbsolute, FString additionalOptions)
{
//Default paths to Maps folder and GameModes folder
FString mapsPath = TEXT("/Game/Maps/");
FString gameModePath = TEXT("/Game/GameModes/");
//Construction of the GameMode option change
FString gameModeOption = TEXT("?game=");
FString gameModeClass = gameMode + TEXT(".") + gameMode + TEXT("_C");
//if GameMode is not set, blank out the variables used to make the game mode option
if (gameMode.Trim().IsEmpty())
{
gameModeOption.Empty();
gameModeClass.Empty();
gameModePath.Empty();
}
//A travel URL is built starting with the map name and append any options
// i.e.: /pathtomaps/map?option=value?option2=value2 ... etc
FString travelURL = mapsPath + mapName + gameModeOption + gameModePath + gameModeClass + additionalOptions;
ProcessServerTravel(travelURL, bAbsolute);
}
Then in the blueprint I just call the GameMode and add the Server Travel node. This is your best bet for a ServerTravel with options.
And is there a certain place where you inserted your code into the header-file? (public/protected/private?)
Or simply at the end of file or just below the ProcessServerTravel function?
I made this function in my own AGameMode class (all you need to do for that is just add c++ class from the editor and pick game mode, it makes a blank class for you to use that extends the base gamemode class).
Alright. That was why I earlier asked about the “original class”. All examples I could find worked with a own class and, thus, I was a bit confused.
After some stupid mistakes, everything seems to work now! I´m not entirely sure yet, as I first have to finish some more BPs, until I can test the function in its final environment… (wanted to get this issue out of the way first, however)
Hi, I have implemented your custom function (in 4.14.1), and it properly travels w all clients to the set map. The game mode is however not changed to the requested game mode. Do I need to add the game mode as a class that shouldn’t persist? It seems like server travel doesn’t care about the set game mode option. Thanks!
the header?
and the other the cpp as you said i guess ^^.
But in the cpp
void AGameMode::MyServerTravel(FString mapName, FString gameMode, bool bAbsolute, FString additionalOptions)
{
//Default paths to Maps folder and GameModes folder
FString mapsPath = TEXT("/Game/Maps/");
FString gameModePath = TEXT("/Game/GameModes/");
//Construction of the GameMode option change
FString gameModeOption = TEXT("?game=");
FString gameModeClass = gameMode + TEXT(".") + gameMode + TEXT("_C");
//if GameMode is not set, blank out the variables used to make the game mode option
if (gameMode.Trim().IsEmpty())
{
gameModeOption.Empty();
gameModeClass.Empty();
gameModePath.Empty();
}
//A travel URL is built starting with the map name and append any options
// i.e.: /pathtomaps/map?option=value?option2=value2 ... etc
FString travelURL = mapsPath + mapName + gameModeOption + gameModePath + gameModeClass + additionalOptions;
ProcessServerTravel(travelURL, bAbsolute);
}
The ProcessServerTravel(travelURL, bAbsolute); is undefined on my cpp. why is that so ?
My Issue on Seamless travel with steam is that if i travel i have no Spawnpoint as Host and the client gets an Fatal Error and the game crashes.
But i need the seamless travel when i use steam dont i ?