# How to use Player State, Game Mode and Game Instance correctly to replicate a variable?

**URL:** <https://forums.unrealengine.com/t/how-to-use-player-state-game-mode-and-game-instance-correctly-to-replicate-a-variable/511556>\
**Category:** Multiplayer & Networking\
**Tags:** Replication, unreal-engine, Multiplayer, Blueprint\
**Created:** [April 1, 2022, 1:51pm UTC](https://forums.unrealengine.com/t/how-to-use-player-state-game-mode-and-game-instance-correctly-to-replicate-a-variable/511556 "2022-04-01T13:51:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paund](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Paund](https://forums.unrealengine.com/u/Paund)\
**Post date:** [April 1, 2022, 1:51pm UTC](https://forums.unrealengine.com/t/how-to-use-player-state-game-mode-and-game-instance-correctly-to-replicate-a-variable/511556/1 "2022-04-01T13:51:19Z")

</div>

Hi everyone, as the title says , I am stuck with the correct replication of a simple variable over the session.  
To be more specific , I’m trying to use the GI to creare and store a Player Name on Event Init, than I want to set another variable on my Player State using the function “Get Game Instance” on PS Begin Play.  
I created a simple Host/Join session without a dedicated server (Up to 3 player in total), and I have a EventOnPostLogin on my GM that collects Player controller and their Player States.  
When I try to print all the names from my PS array, I only get 3 times the name of the server.

I tried searching online, but everyone speaks about the GI as a independent body, that only exist on Client , so why the one that host the session, replicates it’s name on all others?

 ![InkedUiGINQOyyX_LI](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/b/f/bbf8b255affb42c683b92c0782cb4bf4361cc491.jpeg)  
 ![9J4YSPn07N](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/c/4/4c4aa2bb932edcb9845984501988471ec6c67ab5.png)  
 ![U3baWlDrOE](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/d/b/0db89b0a34f87737e75d97e70ca0b947e6af0ad8.png)  
 ![InkedMiEqZsuNlW_LI](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/f/4/ef4ad36d542dd9ba6e5529208c52a2328105c0f2.jpeg)  
 ![CN7gh4gAdz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/7/3/c738404a4ab5be97c62784ce0d95cbaa102a0fa2.png)

---

<div class="post-metadata">

**Author:** ![Naitguolf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Naitguolf](https://forums.unrealengine.com/u/Naitguolf)\
**Post date:** [April 2, 2022, 9:24am UTC](https://forums.unrealengine.com/t/how-to-use-player-state-game-mode-and-game-instance-correctly-to-replicate-a-variable/511556/2 "2022-04-02T09:24:05Z")

</div>

> [@Paund](#):
>
> Player State using the function “Get Game Instance” on PS Begin Play.

Game instance is not replicated, each client has it’s own.  
Game Mode only lives on the server, nor in any client. (No client can access it)

This post explain it a little bit so it might help you better:

> [@Game State, Game Instance & Game Mode. Which one to use for what?](https://forums.unrealengine.com/t/game-state-game-instance-game-mode-which-one-to-use-for-what/399795/2):
>
> Hey, did you check out [eXi’s Network Compendium](http://cedric-neukirchen.net/2017/02/14/multiplayer-network-compendium/)? It’s huge, but important that you understand the whole framework and not only your 3 mentioned classes. I hope it helps you as much as it helped me! \<3

---

<div class="post-metadata">

**Author:** ![HAF-Blade](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/haf-blade/32/88718_2.png) [@HAF-Blade](https://forums.unrealengine.com/u/HAF-Blade)\
**Post date:** [April 2, 2022, 5:49pm UTC](https://forums.unrealengine.com/t/how-to-use-player-state-game-mode-and-game-instance-correctly-to-replicate-a-variable/511556/3 "2022-04-02T17:49:07Z")

</div>

The documentation is really good for these kind if things.

> **[Gameplay Framework Quick Reference](https://docs.unrealengine.com/4.27/en-US/InteractiveExperiences/Framework/QuickReference/)**
>
> Short overview of classes for game rules, characters, controllers, user interfaces, etc., that make up the framework for the game.

---

<div class="post-metadata">

**Author:** ![Paund](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Paund](https://forums.unrealengine.com/u/Paund)\
**Post date:** [April 4, 2022, 7:57am UTC](https://forums.unrealengine.com/t/how-to-use-player-state-game-mode-and-game-instance-correctly-to-replicate-a-variable/511556/4 "2022-04-04T07:57:41Z")

</div>

Yeah, I checked the ue docs , but they just tell me which class I need to use, but not how to properly use them.  
In theory I understand everything, in practice I’m having problems.

---

<div class="post-metadata">

**Author:** ![Paund](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Paund](https://forums.unrealengine.com/u/Paund)\
**Post date:** [April 4, 2022, 8:00am UTC](https://forums.unrealengine.com/t/how-to-use-player-state-game-mode-and-game-instance-correctly-to-replicate-a-variable/511556/5 "2022-04-04T08:00:30Z")

</div>

Thank you, I will study the pdf, it would seem great to understand the functions and methods to use

---

<div class="post-metadata">

**Author:** ![Paund](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Paund](https://forums.unrealengine.com/u/Paund)\
**Post date:** [April 5, 2022, 9:18am UTC](https://forums.unrealengine.com/t/how-to-use-player-state-game-mode-and-game-instance-correctly-to-replicate-a-variable/511556/6 "2022-04-05T09:18:51Z")

</div>

I came to a conclusion, If I have a non-dedicated server, I can’t pass my variable directly from Game Instance in match, because the Server Game Instance will interfere.

Somehow I managed to get it to work using the Save Game to get my variable and the GI to save save them.

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![KillerSneak](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killersneak/32/754802_2.png) [@KillerSneak](https://forums.unrealengine.com/u/KillerSneak)\
**Post date:** [October 11, 2023, 2:13pm UTC](https://forums.unrealengine.com/t/how-to-use-player-state-game-mode-and-game-instance-correctly-to-replicate-a-variable/511556/7 "2023-10-11T14:13:37Z")

</div>

Would get rid of the Delay node OnPostLogin as when 2 player try to connect at the same time within that 0.5 seconds you will miss that players (or both) OnPostLogin event.

---

<div class="post-metadata">

**Author:** ![Wavform](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Wavform](https://forums.unrealengine.com/u/Wavform)\
**Post date:** [February 6, 2024, 4:17am UTC](https://forums.unrealengine.com/t/how-to-use-player-state-game-mode-and-game-instance-correctly-to-replicate-a-variable/511556/8 "2024-02-06T04:17:28Z")

</div>

Can you show us what you’ve done?
