Get the number of players from PIE?

Quick question, is there a way to access this Int with blueprints?

The rounds in my game start only when all players have loaded in from the lobby, when testing directly on the ingame map there is no loading, so I have to set the number manually, id be able to automate this if the Number of Players (opened clients) was accessible

Any help appreciated

in your GameMode exists an Event called

HandleStartingNewPlayer

This Event returns a PlayerController of the newly entered Player.
add this Conzroller to an Array, so you have an Array of Player, that you can get the Length of, that is your current connected Player count.

Thanks for the suggestion, but its not fast enough. I use the Dev Authentication Tool to login to EOS before PIE launches which makes the clients login slower than the server, this causes them to be desynchronized in the beginning. I need the “number of expected players to join” from the get go.


Currently Connected PCs are added to the array OnPostLogin in the game mode.

When setting the Number of Players in the multiplayer settings, that Integer is stored somewhere, that is what I need to get.

this is not the number of players in multiplayer…
this number is just the setup how many PIE/Standalone instances to be spawned to test Multiplayer in a fake and latency free environment.

You need to define the Max Player count per session by yourself with an integer variable and update session settings for max players and current players by yourself.

Yes and the question is how can I access this number with blueprints?

This is just for testing purposes, sometimes i need to test stuff with 1 player sometimes 2 or more. I want to automate the process where the match starts based on how many PIE instances are being launched. Not how many max players there are supposed to be. (This is already handled in a non testing environment)

i don’t think there is a way to get editor settings in runtime.
what you can try is to load the Editor ini file, read it until you get the correct line and take the value as int.

1 Like

This is how the menu gets the number.

int32 FInternalPlayWorldCommandCallbacks::GetNumberOfClients()
{
	const ULevelEditorPlaySettings* PlayInSettings = GetDefault<ULevelEditorPlaySettings>();
	int32 PlayNumberOfClients(0);
	PlayInSettings->GetPlayNumberOfClients(PlayNumberOfClients);	// Ignore 'state' of option (handled externally)
	return PlayNumberOfClients;
}
1 Like

Unfortunately same issue as above, it only registers players as they login. Not useful in my case

If that doesn’t work see if you can supply command-line param that can be passed both to the editor, and also parsed as a runtime command-line string?

Do you have any examples of how this would work?

Is there a way I can run/modify this function to run with blueprints?

@BDC_Patrick has the answer that worked for me.

"(YOURPROJECT)/Saved/Config/WindowsEditor/EditorPerProjectUserSettings.ini

Is the path to the file containing the info, from there you are looking for “PlayNumberOfClients=”

It should be noted I use the plugin Easy CSV to get the “Load String from Local File” node, but there are other ways too.

Note of advice for anyone who wants to do this: to use the ULevelEditorPlaySettings class, you need the UnrealEd module in your Build.cs dependencies. It’s not super obvious because the class isn’t explicitly declared as a part of the UnrealEd API, but it is.

Is there a way to prevent UnrealEd from being packaged? I want to use this for getting a stable net ID while developing locally with PIE.

// Required "UnrealEd " build entry, but I don't want to include that module in my shipped game.
FString UVeilFunctionLibrary::GetNetId(const AController* Controller)
{
#if WITH_EDITOR
	if (const UEditorEngine* EditorEngine = Cast<UEditorEngine>(GEngine))
	{
		TOptional<FPlayInEditorSessionInfo> PieInfo = EditorEngine->GetPlayInEditorSessionInfo();
		if (PieInfo.IsSet())
		{
			static int32 PieNetId = 0;
			PieNetId = (PieNetId % PieInfo->NumViewportInstancesCreated) + 1;
			return FString::FromInt(PieNetId);
		}
	}
#endif
	
	const APlayerState* PlayerState = Controller->PlayerState;
	return PlayerState->GetUniqueId().GetUniqueNetId()->ToString();
}

nvm, I found another post describing how to do this:

1 Like