x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to use different GameModes for one level in a Multiplayer Game with Blueprints?

First of all, I know the different possibilities to set the GameMode for a game/map (Link2). 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++.

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.

ServerTravelScreenshot

To change maps, our prototype uses the ServerTravel command, as it seems to be the best/only option. If we could use Open Level instead, this would allow us to change the GameMode with the passed options...

So, is there currently a possibility to to use different GameModes for one level in a Multiplayer Game with Blueprints?

Product Version: UE 4.10
Tags:
servertravel.jpg (19.8 kB)
more ▼

asked Feb 04 '16 at 11:14 AM in Blueprint Scripting

avatar image

Syrill
212 22 22 31

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

You can create a BlueprintCallable function in C++ that will allow you to use ServerTravel with options in your blueprints.

I made a function in my GameMode as follows:

 UFUNCTION(BlueprintCallable, Category = "Networking", meta = (DisplayName = "Server Travel"))
     void MyServerTravel(FString mapName, FString gameMode, bool bAbsolute, FString additionalOptions);

Then in the .cpp I made

 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.

more ▼

answered Feb 05 '16 at 12:21 AM

avatar image

MajinSephiroth
1.2k 31 8 32

avatar image Syrill Feb 05 '16 at 04:20 PM

So you are not creating a new class and adding your code there, but instead add your function to the "original" AGameMode class?

avatar image MajinSephiroth Feb 05 '16 at 04:25 PM

That is correct

avatar image Syrill Feb 05 '16 at 05:12 PM

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?

avatar image MajinSephiroth Feb 05 '16 at 06:05 PM

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).

Try not to modify core unreal engine classes :)

avatar image Syrill Feb 05 '16 at 07:03 PM

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. :D

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)

Thank you very much for your time and help! :)

avatar image Dex82 Mar 26 '18 at 07:41 PM

Hey, i was trying to add your code in a new cpp class ive made but im not so good in cpp. Is the first you posted

 UFUNCTION(BlueprintCallable, Category = "Networking", meta = (DisplayName = "Server Travel"))
 void MyServerTravel(FString mapName, FString gameMode, bool bAbsolute, FString additionalOptions);

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 ?

avatar image Fantasifall Jan 04 '17 at 02:23 AM

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!

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question