# Proper architecture for updating a UI in a lobby system

**URL:** <https://forums.unrealengine.com/t/proper-architecture-for-updating-a-ui-in-a-lobby-system/96666>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [July 18, 2017, 5:56am UTC](https://forums.unrealengine.com/t/proper-architecture-for-updating-a-ui-in-a-lobby-system/96666 "2017-07-18T05:56:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelWion](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MichaelWion](https://forums.unrealengine.com/u/MichaelWion)\
**Post date:** [July 18, 2017, 5:56am UTC](https://forums.unrealengine.com/t/proper-architecture-for-updating-a-ui-in-a-lobby-system/96666/1 "2017-07-18T05:56:57Z")

</div>

Allow me to run a little scenario for you…  
My project has a blank “LobbyMap” containing the following setup:

- _LobbyGM_ (AGameMode)
- _LobbyGS_ (AGameState)
- _LobbyPS_ (APlayerState)
- _LobbyPC_ (APlayerController)
- _LobbyWidget_ (Full screen container widget, with a “Ready To Play” button at the bottom)
- _PlayerEntryWidget_ (Template widget for displaying a player’s name, avatar, ready state, etc)

So “Bob” runs the standalone game, and chooses “Host” from the main menu. This creates a session (via Steam OSS) and loads the lobby map for Bob, who is now the listen server.

Client-side things that should happen for Bob:

- Create & display an instance of _LobbyWidget_
- Populate Bob’s _LobbyWidget_ with a single instance of _PlayerEntryWidget_, which reflects Bob’s player info

Then “John” runs the game, and chooses “Join” from the main menu. He is presented with a session search result dialog, and can see Bob’s session.  
John joins Bob’s session, which automatically loads the lobby map for him as a client. Bob receives a login notification.

Client-side things that should happen for John:

- Create & display an instance of _LobbyWidget_ for John
- A new _PlayerEntryWidget_ should be created reflecting John’s player info

Now comes the fun part… How do I update both Bob _AND_ John’s UIs to reflect the fact that both players exist in the lobby?  
And then, if John presses the “Ready To Play” button, how should this be communicated so that both Bob, John, and all future logins know that John is ready?  
Which RPCs should be used, and where?

NOTE: I already understand the basics of working with UMG in both C++ and BPs, as well as all the session hosting/joining stuff.  
I’m mostly concerned about where my data should be kept, how it should be referenced, and how to properly replicate that data in a way that ALL players UI’s can clearly see

---

<div class="post-metadata">

**Author:** ![unit23](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/unit23/32/1223962_2.png) [@unit23](https://forums.unrealengine.com/u/unit23)\
**Post date:** [July 18, 2017, 6:16am UTC](https://forums.unrealengine.com/t/proper-architecture-for-updating-a-ui-in-a-lobby-system/96666/2 "2017-07-18T06:16:43Z")

</div>

I think what you want is the YourGameInstance

> [@](#):
>
> The GameInstance exists for the duration of the engine’s session, meaning that it is created when the engine starts up and not destroyed or replaced until the engine shuts down. A separate GameInstance exists on the server and on each client, and these instances do not communicate with each other. Because the GameInstance exists outside of the game session and is the only game structure that exists across level loads, it is a good place to store certain types of persistent data, such as lifetime player statistics (e.g. total number of games won), account information (e.g. locked/unlocked status of special items), or even a list of maps to rotate through in a competitive game

> **[Networking Overview](https://docs.unrealengine.com/5.3/en-US/networking-overview-for-unreal-engine/)**
>
> Setting up networked games for multiplayer.

The GameMode for functions to count joined players, GameState for more general functions like assigning IDs.

---

<div class="post-metadata">

**Author:** ![MichaelWion](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MichaelWion](https://forums.unrealengine.com/u/MichaelWion)\
**Post date:** [July 18, 2017, 6:48am UTC](https://forums.unrealengine.com/t/proper-architecture-for-updating-a-ui-in-a-lobby-system/96666/3 "2017-07-18T06:48:05Z")

</div>

Well, the [Network Compendium](http://cedric-neukirchen.net/Downloads/Compendium/UE4_Network_Compendium_by_Cedric_eXi_Neukirchen.pdf) doesn’t actually state the use of AGameInstance anywhere. My guess is that it has nothing to do with networking, and only exists client-side.  
It would probably be something I’d use to persist data during a server travel, I guess? But not so much a place to store Player/UI data?

AGameMode only exists server-side, so clients can’t access it directly.  
AGameState exists on both client and server, but I’ve had trouble accessing it from clients.  
APlayerState is replicated to all clients, and each APlayerController owns one, but (AFAIK) you can’t access the UI from APlayerState

So if I made a struct like this:

```auto

USTRUCT(BlueprintType)
struct FLobbyPlayerInfo
{
	GENERATED_BODY()

public:
	UPROPERTY(BlueprintReadWrite)
	FString PlayerName;
	UPROPERTY(BlueprintReadWrite)
	FUniqueNetIdRepl PlayerId;
	UPROPERTY(BlueprintReadWrite)
	bool PlayerReady;
	UPROPERTY(BlueprintReadWrite)
	UTexture2D *PlayerAvatar;
};

```

Where could I store an array of these, where the server has authority over them BUT ALSO clients can request changes to them from their UIs?

---

<div class="post-metadata">

**Author:** ![unit23](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/unit23/32/1223962_2.png) [@unit23](https://forums.unrealengine.com/u/unit23)\
**Post date:** [July 18, 2017, 12:27pm UTC](https://forums.unrealengine.com/t/proper-architecture-for-updating-a-ui-in-a-lobby-system/96666/4 "2017-07-18T12:27:26Z")

</div>

> [@MichaelWion;738174](#):
>
> Where could I store an array of these, where the server has authority over them BUT ALSO clients can request changes to them from their UIs?

Just noticed that you posted in C++, i currently work on setting this up myself, but with blueprints.

For blueprint I plan to use a combination of this example (taken from the Advanced Social System marketplace pack), maybe it gives you an idea.

 ![gs.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/3/7/8377f3052c941aa76d3374bfd335c0eccaa0eef1.png)
