Reading Variable From Gamemode As a Client

A project of mine uses a Gamemode class to base logic where enemies spawn in waves, which has an integer variable called CurrentWave.

All players have a HUD that displays the current wave, however, I’ve had difficulties replicating the integer variable from the Gamemode to the client. From what I’ve read, Gamemodes only exist on the server, thus calling RPCS or replicating variables wouldn’t change anything apart from itself.

I’ve tried using a for-loop on the Gamemode per tick to loop through all existing PlayerControllers, then setting another replicated integer variable on that, so it would (hopefully) replicate to the client and could be read by the HUD, but it only just works on the server and not the client.

I am ears open to anyone who can correct me since my understanding on networking is fragile.

I believe the easiest (and the clearest) solution would be to store CurrentWave in GameState instead. As it lives on both server and client, your GameMode can work with it, while clients can access it, without manual hassles.

I’ve actually used the Gamestate before trying out the PlayerController, until I decided to give it another go, then realising that the variable in GameState never replicated. I forgot to mention that the int CurrentWave was in a replicated struct, in which I also forgot to add UPROPERTY() on top of each variable. Now it works fine :slight_smile: