Set Game Instance Variable in Game Mode to access from Widget

Hello,

I have a player list on my custom GameMode blueprint. I create a function (also in game mode) which will loop through all players and find the player with the most kills.

This most kills player is then assigned to the MostKills variable on the GameInstance

From my widget (which exists on every client) I get the game instance and fetch the value of this MostKills.

A problem I am seeing is that if I print the players name in the game mode, I can see it is being set to something like “Player 1” but then - simultaneously I print the string in the widget for what it is fetching from the game instance when binding the name, and it is empty.

I know that the widget cannot access the game mode since it is running on the server and widget is running on the client, but how come the value of my MostKills is not persisting to the GameInstance?

Even if I set the variable to be replicated it is still not happening.

FYI this is for a networked game. Please let me know if anyone has any suggestions, I’d be happy to provide more details.

GameMode class does not replicate to clients. It doesn’t even exist there (it is NULL).

GameInstance doesn’t have any replication mechanisms either, although it does exist on both server and clients, they are independent.

The right place to do this is GameState. It’s a singleton on server that replicates to everyone.
GameState already has a builtin PlayerArray variable that contains all player states and is synchronized. Just iterate that array to find who has most kills.

1 Like