I am trying to update a widget across all the players in the game for how many parts they have collected. But I can’t for the life of me get it to update to all the clients and server.
When I press R it checks if the player that pressed the key has authority, and responds accordingly. Then it will call an event in the widget from the server for all clients to update the collected number.
2 things go wrong during testing. 1) The variable is unique to each client. (If I press are 3 times on server, nothing changes on clients and vice versa)
And 2) I get an error that the HUDRef accessed none when running the multicast.
Here is a screenshot of my blueprints: Imgur: The magic of the Internet
Any help would be greatly appreciated and relatively new to replication and have been working at this for a while.
Widgets run on client only I would suggest putting the info to share in game mode or game instance. Then access that in the widget.
GameMode only exists on the server and is not replicated to clients, GameIstance is not replicated at all and every client has their own instance.
A few multiplayer concepts will be helpful here:
- Widgets are client-side only, not replicated at all.
- Clients can only call Server RPCs on Actors they ‘own’ (usually just character/pawn and player controller)
- Player controllers are only replicated to the ‘owning’ client
- GameState is replicated to all.
- GameMode only exists on server.
- GameIstance is not replicated at all.
How I would do this:
- Make a Server RPC on player controller called Server_IncrementCollected.
- In PlayerController add Input R event and call Server_IncrementCollected.
- In Server_IncrementCollected, increment a RepNotify integer property on your GameState.
- In the RepNotify function on Gamestate, do any logic responding to the value being updated.
- In your widget, you can bind text/UI to a function that gets the value from GameState.
Hope this helps.
Yes that’s why replicating from game mode will always give the server side result. Replicating it to game instance means all clients receive the servers result. You can achieve this with custom events. If logic needs to be done client side then yes this approach is not appropriate.
Ah yes I worded that completely wrong sorry broke arm yesterday not communicating very well lol
Oh that sucks! Hope it heals quickly!
Cheers i think I’ll leave the answers till I’m not on pain killers