How to have the server restart the level?

Hello!

I can succesfully check wheter one team or the other wins (After checking which team has no members alive). Next, I want to restart the map. Imagine like Counter Strike, where after certain time or a team wins, the server restarts for a new round. How can I do this?

I tried implementing a console command “RestartLevel”, but it doesnt work when I test with 2 or more players running.

Then I tried creating a variable in the Game Mode for the current Level Name. Then I tried to simply call the node for OpenLevel, and pass the current level there. However, what ends up happening is that while the server restarts correctly. The client starts in the default example map!

http://puu.sh/eQraH/a0faf25525.jpg

How do I get this to work?
Thanks!

EDIT. I did a test with 5 players, and it seems like evry single client transforms into it’s own server and everyone has it’s own instance of a game.

http://puu.sh/eQs5z/68ba203995.jpg

1 Like

Anyone? Please!

this is the blueprint code I am using.

http://puu.sh/f3BJJ/f4d912d4ec.png

This crashes the editor when I test it. This is the blueprint code I have.

http://puu.sh/f3Kfn/9d3475fc3c.png

You need to call “ServerTravel mapname” on the server itself for the server to be taking everyone along. Doing “Open Level” is what causes everyone to have their own map going.

Hope it helps :slight_smile:

1 Like

Before you do your execute console command, do a “Has Authority” check and on “Authority” execute the console command.

That code is in the game mode, so it only exists on the server. It crashes anyways with the “Switch Has Authority” node. :frowning:

Does it crash when you try to run it, or does it crash when you reach that point in the blueprint?

Do you have a space after ServerTravel?

Is the output from “Current Level” the proper name of the map?

I’ve used ServerTravel and it hasn’t produced a crash for me, which makes me wonder what could be causing it.

I created a small function inside of my multiplayer Game Mode as demonstrated below, and overwrote one of my server events in the Player State to call it. Since the event is set to run on server, client or host were both able to trigger it just fine.

Can you try to replicate this on another map with a different game mode?

It crashes when it reaches that point in the code.

Yes, I do have a space between map names. Else, the game won’t detect the command.

It crashes when I run 2 or more players in the game (With 1 player it doesn’t crash).

It even crashes when I use it a console command directly.

Using the servertravel command in the example map also crashes. You can use the command with multiple clients, right?

I tried it with UE4.7, using the first person template. It relaunched the server, but the client was stucked, I couldn’t move with him. And then I tried restarting again and it crashed.

Using the command directly, I didn’t bother with blueprints for this test.

Yep! You’re supposed to use it with multiple clients :slight_smile:

Can you try it in a blank project?

One more thing I’d like you to test, instead of going through the editor and using the play in editor option, could you launch two instances of the game from your .uproject inside of your project folder.

Make one the host, the other one join, then on the host run the ServerTravel command.

I don’t know how to do that :frowning:

No worries!

  • Go to your “Unreal Projects” folder (usually inside of Documents)
  • Go inside your project folder
  • Right click on your “projectName.uproject”
  • Choose “Launch Game”
  • Do it again (the second will be used as a client)

Now in one of them do a console command for open level?listen and in the other one open 127.0.0.1

Now do your ServerTravel Map test on the server.

I want to say about this issue. I also was stuck with restarting my map and found this post. I tried to do this in the editor, but I had the same symptoms as Motanum had.

But then I tried to do the same things in my packaged game. (I created a session and client joined it with appropriate blueprint nodes). And ServerTravel worked correctly. Both of server and client characters respawn at their start position and have initial inventory state. So, I think it’s necessary to mark this post as Bug report (To fix editor crash)

Set seamless travel true in defaults settings in game mode, create blank map called Travel and set the map in project settings under transition map. Common thing is also setting default gamemode in the project settings. On the maps you play in world settings use your custom gamemode.
Then you can use ServerTravel command on the server(host).