Character and Pawn is null on logout?

I am trying to, on player logout (either they closed game, or got disconnected), store the actor location of their character.

I have tried two built in method overrides:

  1. AGameMode::Logout(AController * Exiting)
  2. APlayerController::EndPlay(const EEndPlayReason::Type EndPlayReason)

In either method, when I get the pawn or character from the controller it seems to already have been destroyed by the time this method is called so it is null.

Does this sound right to you? And if so, is there any other way to get the player’s last position on logout? Or do I just need to cache that somewhere (perhaps player state) on a recurring interval if I want to read it on logout?

Any help would be greatly appreciated!

Figured it out! PawnLeavingGame is the method you want inside the player controller. It is the method that destroys the pawn, so you can override it and call GetPawn() inside of it to get your pawn and read its location/store in db, etc, then call the super() method to proceed with the deletion of the pawn.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.