How to use OpenLevel() with multiple player starts?

I have multiple player starts in a level and want the destination to be able to change. How can I use OpenLevel() to spawn the player at a specific one of these player starts?

Thanks in advance

Does that change depends on the previous level? If so, why messing aroung with OpenLevel when you can, for example, use GameInstance.

In game mode there is a function called FindPlayerStart which is a BlueprintNativeEvent. Which means you can override the function:

AActor* FindPlayerStart_Implementation(AController* Player, const FString& IncomingName);

Override this function in your gamemode for the level and iterate through your playerstarts and return the one that is suitable.

I know how to find the correct player start. How do I use that to have the player spawn there with OpenLevel()?

Pass the identification of the player start you want in the option box.

In this function you get the PlayerController, so write your code to find the player start here and return the player start. Player with that controller will automatically spawn at that player start that is returned in this function.
You dont have to do anything extra for player to spawn at that player start other than returning the player start in this function. Spawning player at that start location is handled by UE4 as long as you return the correct player start.

“Options String”. Now it’s up to you to parse it.

Example. If

Then “Options String” will have the string "qwe asd askljdakjskajkljskdljfskldjf ".

1 Like

How do you use the option parameter? I couldn’t find a single piece of documentation on it anywhere. Not even Unreal’s documentation explains how to use it.

But I’m using C++

It depends on an instance of a user-created actor

C’mon dude. It’s all there.

To open a level:

UGameplayStatics::OpenLevel(this, FName("/Game/tests/map1"), false, "XXX");

The options string is in:

OptionsString

in the game mode.

For example, if in the game mode you write this up:

void AFPCPPGameMode::BeginPlay()
{
	Super::BeginPlay();
	UE_LOG(LogTemp, Warning, TEXT("Options > % s"), *OptionsString);
}

It will log “Options > XXX”.

1 Like

Can you explain what the problem with my solution is? You wanted to specify which player start you wanted in the Open Level. So, I gave it to you.

All you have to do is set the “Player Start Tag” tags in all Player Start actor (which one of them should match with the string you going to pass in the options) and override ChoosePlayerStart function in the gamemode.