I’m making a multiplayer game. I want to keep the player character actor of a client that left the game, in the game for a while.
What is, and where is the destroying of the player character controlled?
I’m making a multiplayer game. I want to keep the player character actor of a client that left the game, in the game for a while.
What is, and where is the destroying of the player character controlled?
Can I get an answer on this please? Even to confirm that it can’t be done.
It’s not completely clear what you want happening. If a player disconnects from the game, why leave him in there.
you can setgamepaused, disableinput, setvisibility to make him disappear without destroying him…and after a delay destroy him if you want later or attach it to some event
usually you just fake death and not actually destroy. Hope this points you in the right direction…
Thanks for your answer!
The reason why I need the character to stick around for a while after the client disconnected is so that the player can’t use quitting the game as a way to escape battle.
I want to delay the destroying of the character actor for some time or to be re-possessed by the client if it should reconnect before that happens.
I haven’t found any way to control what happens to the character after client leaves though.
I think I’m on to something. I tried unpossessing the char before I quit the game and that actually did leave the char behind on the server when the client disconnected. Only problem now is that I doesn’t seem to work if I do it using the end play node. It’s like it’s too late and the char has already started the process of leaving the level.
Any ideas how I can override this behavior? :I
Finally got it working! With some much appreciated help from CodeSpartan, I managed to create a new C++ class for the PlayerController that overrides thePawnLeavingGame() to NOT destroy the character.
These are the steps:
Create a new C++ class from the Add
New button in the editor. I named it
“NewPlayerController”.
In Visual
Studio edit the new files,
“NewPlaterController.cpp” and
“NewPlayerController.h”, you just
created.
This is what the .ccp should
look like:
#pragma once
#include “GameFramework/PlayerController.h”
#include “NewPlayerController.generated.h”
UCLASS()
class CLEANTHIRDPERSON_API ANewPlayerController : public APlayerController
{
GENERATED_BODY()
virtual void PawnLeavingGame() override;
};
And this is what the .cpp should look like:
#include “CleanThirdPerson.h”
#include “NewPlayerController.h”
void ANewPlayerController::PawnLeavingGame()
{
if (GetPawn() != NULL)
{
UnPossess();
SetPawn(NULL);
}
}
Save and go back to UE and hit the compile button.
After the game has compiled you can change your
playerController to iherit from this
NewPlayerController instead of just
PlayerController!
I hope this helps other people out there. It sure caused me a lot of frustration!