So what I need to do is possess a pawn (in this case a vehicle) but have it unpossess and not be destroyed when the player exits or disconnects.
That way the vehicle can be possessed by another player for example.
Problem is the vehicle is destroyed before the controller so there is no easy way of doing that.
How would you go about doing this? There should be an easy way for something like this… Any help would be greatly appreciated.
I’m assuming from your post that this is a multiplayer game. I’m not super solid on the multiplayer aspects of UE4, but if I understand correctly, so long as you do not destroy the vehicle on the server when you disconnect the player (on logout) the vehicle should still remain – if it is not actively possessed by a player; however, I think the issue you’re running into is that the pawn is getting removed because it is possessed by a player controller on disconnect.
To resolve this, you can try to using either the Pawn > Un Possess node in Blueprints or using the APlayerController::UnPossess() method() to separate the player controller and pawn before disconnecting the player.
Hope that helps, if not, well at least I tried.
Best of Luck
I found a solution for my problem… i guess its the same then yours. In my gamemode BP i want to store in the “OnLogout” several informations of the player pawn, like position, but the pawn is already destroyed in the “OnLogout” by the Unpossess’ing.
So i didnt found a way in BP honestly… my solution for it is to overwrite the UnPossess() of my custom class C_PlayerController and override the “UnPossess()” method to store stuff from the Pawn before it gets unpossessed further. In BP i then just use the value of my storeage variable “unpossessPawnTransform”.
The Header part:
UCLASS()
class CLIENTSERVERTEST_API AC_PlayerController : public APlayerController
{
GENERATED_BODY()
public:
/** Stores the transformation of the unpossessed pawn */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=PlayerController)
FTransform unpossessPawnTransform;
virtual void UnPossess() override;
};
The CPP part:
void AC_PlayerController::UnPossess()
{
UE_LOG(LogTemp, Warning, TEXT("UnPossess()"));
if(this->GetPawn() != NULL)
{
UE_LOG(LogTemp, Warning, TEXT("UnPossess() i got some pawn"));
this->unpossessPawnTransform = this->GetPawn()->GetActorTransform();
this->unpossessPawnTransform.DebugPrint();
}
else
{
UE_LOG(LogTemp, Warning, TEXT("UnPossess() dont have a pawn here too, wtf"));
}
APlayerController::UnPossess();
}
The redefinition source is in the code:
UnrealEngine\Engine\Source\Runtime\Engine\Classes\GameFramework\PlayerController.h
UnrealEngine\Engine\Source\Runtime\Engine\Private\PlayerController.cpp
And now the destruction can be regulated through the Blueprints! Yess!
I hope this will add to the standard functionality. After all, the weight of this code is only 138 bytes, and the use of space.
UCLASS()
class MYGAME_API ASubPlayerController : public APlayerController
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "OnPawnLeavingGame"))
void ReceivePawnLeavingGame(APawn * aPawn);
virtual void PawnLeavingGame() override;
};
in SubPlayerController.cpp :
void ASubPlayerController::PawnLeavingGame()
{
// This part is the original destroying effect. Remove if unwanted
// if (GetPawn() != NULL)
// {
// GetPawn()->Destroy();
// SetPawn(NULL);
// }
//
ReceivePawnLeavingGame(GetPawn());
}
And voila! You can manually destroy or not the pawn in BP: