UGameplayStatics::OpenLevel
#include "Kismet/GameplayStatics.h"
Access: public
Specifiers: static
Description
Travels to a new level by name, unloading the current world. This is a hard travel — all actors are destroyed and gameplay state is reset.
Signature
static ENGINE_API void OpenLevel(const UObject* WorldContextObject, FName LevelName, bool bAbsolute, FString Options) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Any valid UObject in the world. | — |
| LevelName | FName | The short name of the level asset (e.g. 'MainMenu', not the full path). | — |
| bAbsolute | bool | If true, unloads all current levels first. If false, appends to the current world. | true |
| Options | FString | URL options string appended to the travel URL (e.g. '?listen' for a listen server). | "" |
Return Type
void Caveats & Gotchas
- • Hard travel destroys everything in the current world. Persistent data (scores, settings) must be saved before calling — use a GameInstance for cross-level state.
- • LevelName must match the asset name exactly (case-sensitive on some platforms). Do not include the path or file extension.
- • For seamless travel that preserves PlayerControllers and GameState across levels, use AGameModeBase::ProcessServerTravel or APlayerController::ClientTravel with TRAVEL_Relative.
- • Calling OpenLevel during BeginPlay or from within a delegate may cause crashes on some engine versions — defer it with a timer or SetTimerForNextTick if needed.
Example
Return to main menu and start a listen server C++
// Simple level load
UGameplayStatics::OpenLevel(this, FName("MainMenu"));
// Start a listen server on a map
UGameplayStatics::OpenLevel(this, FName("GameMap"), true, TEXT("?listen")); See Also
Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?