Player Join/Exit Event

Is there a way to be notified that a new player has joined or an existing player has exited a match? Maybe an event of some kind?

Bonus: Something similar for bots spawning or being removed?

Hi Sidno,

I believe, but am struggling to find documentation and am fairly new to the unreal engine, that you can achieve this through setting up a Player Controller or Pawn (not sure) class for the level that you are on and set them through the world settings. Then add an Event Being Play and End Play which should handle the join and leave events.

I would probably use a Player Controller then (for a lobby at least) when a player joins the controller is created on the server only (as well as the owning client) and it is destroyed on the server when it looses contact. So then you could multicast the begin play and end play events with custom events to do what you wish.

Regards,
Josh

Since you posted this in c++, you can use all GameMode Methods for that. For example:

Thanks eXi. These are pretty handy functions.However I am having problems with the AGameMode::Logout - Function. Here is what I wrote:

void ASomGameMode::Logout(AController* Exiting)
{
    ASomCharacter* SomChar = (ASomCharacter*)(Exiting->GetPawn());

   if(SomChar)
     //do some things

}

The Logout-Function receives a valid Player Controller, but the controlled pawn of this PC always is NULL. Maybe the Pawn is destroyed before this function is called? Is there a way to do some things with the pawn before it gets logged off/ deleted?

I would like to know too, do you found any solution ?

Same here.

I don’t know if the PlayerCharacter, which is possessed when leaving, is already destroyed at that point. But if you experience this, you might want to handle the stuff directly in the Character.

You could, for example, use the “EndPlay” function that every AActor and its Children have:

Hey there. In the end I did solve my Pawn-Problem with the PlayerController which posseses the pawn. To be exact, I did override the “PawnLeavingGame()”-Function inside the PlayerController-Class:

https://answers.unrealengine.com/questions/335074/how-to-read-pawn-values-while-player-disconnect.html

void ASomPlayerController::PawnLeavingGame()
{
	//Get Controlled Pawn
	ASomCharacter* SomChar = Cast<ASomCharacter>(GetPawn());

	if (SomChar)
	{
		//Do some things with the char
	}
		

	Super::PawnLeavingGame();
}