Change Levels c++

hi I am trying something simple, just to change from 1 level to another when a button is clicked.
I am using the line
UGameplayStatics::OpenLevel((), TEXT(“World’/Game/Maps/Level1.Level1’”), TRAVEL_Absolute);
however when I click the button to load a new level, the game closes as if I hit esc. I’m not sure why and id like to figure it out. I think maybe its my params but I’m not sure what else to try.

In PIE? It might be because editor dont want to load new level, considers it as level end, it stop PIE to let you continue editing level. Primery funtion of PIE is level testing not playing full game. Try using standalone

If its some error something should be printed in log

Might be your arguments - try travelling using the console commands to see if you still have a problem:

LocalTravel <URL>

or

Travel <MapName>

Hey King Pete-

I setup a function in my Character.cpp to test changing levels with the same general code that you have. I setup an input in the project settings and then bound that input in my Character: InputComponent->BindAction("SwitchLevel", IE_Pressed, this, &ACodeLevelChangeCharacter::SwapLevel);

The SwapLevel function then looks like:

void ACodeLevelChangeCharacter::SwapLevel()
{
	UWorld* TheWorld = ();

	FString CurrentLevel = TheWorld->GetMapName();
	
	if (CurrentLevel == "ThirdPersonExampleMap")
	{
		UGameplayStatics::OpenLevel((), "Level2");
	}
	else
	{
		UGameplayStatics::OpenLevel((), "ThirdPersonExampleMap");
	}
}

In a standalone game this will change the level I’m on to the ThirdPersonExampleMap (default level). This should help give an idea of how you can switch levels through code. As mentioned this doesn’t work during PIE and requires using standalone instead.

Cheers

I tried this in UE4.15 and it does work in editor

Travel works based on package names, not based on object names. /Game/Maps/Level1.Level1 is an object, while /Game/Maps/Level1 is its package. So instead of

UGameplayStatics::OpenLevel((), TEXT("World'/Game/Maps/Level1.Level1'"), TRAVEL_Absolute); 

you need to use

UGameplayStatics::OpenLevel((), TEXT("/Game/Maps/Level1"), TRAVEL_Absolute);