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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How to reset level in C++?

Hey there,

does anyone know how to easily reset the level in C++? I thought there would be a function that does that inside the UWorld class, but I couldn't find any.

I also tried this "hack":

GetWorld()->Exec(GetWorld(), TEXT("RestartLevel"));

But it doesn't seem to work either (any idea why?)...

// Edit: playerController->ConsoleCommand(TEXT("RestartLevel")); seems to do the trick, but whats the clean way of doing this, that also works in a multiplayer game?

Product Version: Not Selected
more ▼

asked Jul 27 '14 at 09:07 PM in C++ Programming

avatar image

90 7 9 109

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

If this is a standalone game and maybe multiplayer server.

You can do the following command with ?restart.

ClientTravel( TEXT("?restart"), TRAVEL_Relative );

      * Travel to a different map or IP address. Calls the PreClientTravel event before doing anything.
      * NOTE: This is implemented as a locally executed wrapper for ClientTravelInternal, to avoid API compatability breakage
      * @param URL                A string containing the mapname (or IP address) to travel to, along with option key/value pairs
      * @param TravelType         specifies whether the client should append URL options used in previous travels; if true is specified
      *                            for the bSeamlesss parameter, this value must be TRAVEL_Relative.
      * @param bSeamless            Indicates whether to use seamless travel (requires TravelType of TRAVEL_Relative)
      * @param MapPackageGuid    The GUID of the map package to travel to - this is used to find the file when it has been autodownloaded,
      *                             so it is only needed for clients

void ClientTravel(const FString& URL, enum ETravelType TravelType, bool bSeamless = false, FGuid MapPackageGuid = FGuid());

This how the controller does it in the codebase. Hope that helps :)

more ▼

answered Jul 27 '14 at 10:30 PM

avatar image

2.3k 114 62 233

avatar image shadowcoder31 Jul 28 '14 at 12:11 AM

Thanks, this works perfectly in singleplayer, but in a multiplayer match in the editor this results only in a respawn of all playercontrollers and in a standalone game its even worse, it results in a disconnect of all clients. I am calling the function on the listen server as well as on all the clients.

Also, I just found a ServerTravel function in the UWorld class. However, GetWorld()->ServerTravel(TEXT("?restart")); doesn't seem to work (clients get disconnected)... :(

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Okay, so maybe this one will help you under your

AGameMode::ProcessServerTravel(const FString& URL, bool bAbsolute)

and make sure that you have bUseSeamlessTravel set true;.

  * perform map travels using SeamlessTravel() which loads in the background and doesn't disconnect clients
  * @see World::SeamlessTravel()
 uint32 bUseSeamlessTravel : 1;

Actually the more I look, it seems that

void UWorld::SeamlessTravel(const FString& SeamlessTravelURL, bool bAbsolute, FGuid MapPackageGuid)

Is what you want. The information in World.cpp has some great info and says it doesnt' disconnect the clients. :)
Good Luck!

more ▼

answered Jul 28 '14 at 01:02 AM

avatar image

2.3k 114 62 233

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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