# Spawn with same character on dedicated server

**URL:** <https://forums.unrealengine.com/t/spawn-with-same-character-on-dedicated-server/443246>\
**Category:** Character & Animation\
**Tags:** dedicated-server, playerstate, gamestate, unreal-engine, CPP, question\
**Created:** [February 12, 2019, 5:30pm UTC](https://forums.unrealengine.com/t/spawn-with-same-character-on-dedicated-server/443246 "2019-02-12T17:30:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![NemoLArs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NemoLArs](https://forums.unrealengine.com/u/NemoLArs)\
**Post date:** [February 12, 2019, 5:30pm UTC](https://forums.unrealengine.com/t/spawn-with-same-character-on-dedicated-server/443246/1 "2019-02-12T17:30:14Z")

</div>

Hello everyone!

Im the dev of “Corma” (game is free on steam). I have a big issue that i cant solve by my self.

I have a dedicated server that players can join and play on. Which they are. But i have a problem. When a player leaves the game and then tries to join the server again the player gets a new character with an empty inventory. So now he/she cant use thier old stuff they crafted or placed because thier are not the owner.

However if i restart the server, everyone will spawn in as that character they made the first time on the server.

Ive tried to read on google and on forums and it seems that on default the game state or player state is deleted on disconnect, but my save system saves them. Thats why its working after restart?

The thing i want to do is to remove that delete on playerstate so if the same steam ID64 joins the server he will posses that same pawn and get the same char. Hopefully someone will understand and have an idea on what to do 😃

Thanks in advance  
Nemo

---

<div class="post-metadata">

**Author:** ![Chyros](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chyros](https://forums.unrealengine.com/u/Chyros)\
**Post date:** [February 12, 2019, 6:04pm UTC](https://forums.unrealengine.com/t/spawn-with-same-character-on-dedicated-server/443246/2 "2019-02-12T18:04:35Z")

</div>

1. On GameMode OnLogout, save the PlayerController’s PlayerState on a map (i.e. PlayerStateMap) based on its SteamID as key.
2. On GameMode OnPostLogin, restore PlayerState from a map if it contains the player SteamID key. Otherwise, its a new player.

GameState isn’t deleted on player disconnect as it lives on server. Restarting a level recreates a GameState.

PlayerState gets destroyed after the player logs out so save it OnLogout and restore it when the player with the same SteamID reconnects.

You can save your PlayerState map on GameInstance so it persists even on load level.

---

<div class="post-metadata">

**Author:** ![NemoLArs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NemoLArs](https://forums.unrealengine.com/u/NemoLArs)\
**Post date:** [February 12, 2019, 6:13pm UTC](https://forums.unrealengine.com/t/spawn-with-same-character-on-dedicated-server/443246/3 "2019-02-12T18:13:28Z")

</div>

Thanks for answer! will try that 🙂

---

<div class="post-metadata">

**Author:** ![NemoLArs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NemoLArs](https://forums.unrealengine.com/u/NemoLArs)\
**Post date:** [February 12, 2019, 7:21pm UTC](https://forums.unrealengine.com/t/spawn-with-same-character-on-dedicated-server/443246/4 "2019-02-12T19:21:11Z")

</div>

Hmm… i dont really understand what you mean with “restore”? Ive made so the gamemode is checking if its a new or old. But if its an old one, what do i do so the player gets the same character etc?

---

<div class="post-metadata">

**Author:** ![Chyros](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chyros](https://forums.unrealengine.com/u/Chyros)\
**Post date:** [February 12, 2019, 7:51pm UTC](https://forums.unrealengine.com/t/spawn-with-same-character-on-dedicated-server/443246/5 "2019-02-12T19:51:42Z")

</div>

Since the old Pawn of the player is already destroyed when he logs out, you need to recreate a new Pawn for him. Just “restore” or recreate the old state of the Pawn when he last logs out (i.e., bring back the old items from his inventory that is saved and being keep tracked on your PlayerState - i hope).

Basically, the things that you need to persist when the player logs out (i.e., items he was carrying, his health, etc…) needs to be saved on your PlayerState. So when he logs back, just recreate those on a new Pawn as if he didn’t realize that his Pawn was new because the state was restored.

---

<div class="post-metadata">

**Author:** ![NemoLArs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NemoLArs](https://forums.unrealengine.com/u/NemoLArs)\
**Post date:** [February 12, 2019, 9:05pm UTC](https://forums.unrealengine.com/t/spawn-with-same-character-on-dedicated-server/443246/6 "2019-02-12T21:05:41Z")

</div>

Oh okey i get it! Ill try that! thanks.
