Inventory(networked) - Update Client UI

Hi, I would like to use a RepNotify Array for an Inventory System, and multiple item in the array may change in 1 frame.

So, I would like to know if setting multiple times a RepNotify variable in the same frame will call multiple times the RepNotify_Function on clients?

eg. If I do this, I noticed that the OnRep_Function is called only 1 time on Client. Is it the case every time?

304925-annotation-2020-06-20-040545.png

Regards

This is actually a pretty typical thing in game engines. If you’re using variable replication like this, then you won’t get multiple updates for every time a variable changes. You’ll get some snapshot of it at the time the network API decided to sample the variable. Unreal is no exception here.

So if you add three items to your inventory in a frame, then the client should eventually get an update containing those three items (aside from weird edge cases like you remove those three items again and there’s a ton of packet loss that means that a client never gets the update containing those three items… I can’t remember if Unreal’s variable replication is “reliable”, but I’d assume that it isn’t), but you won’t get three separate RepNotifies, that’s not how variable replication works.

The only way to get multiple notifications like that is to use RPCs, but I wouldn’t recommend doing things that way. In general in multiplayer games it’s better to just use variable replication and live with the fact that there might be some weird edge cases where your client is temporarily out of sync, but that it will eventually get back into sync with the latest version.

Variable replication is reliable however intermediate changes might be skipped and only the latest change will arrive which is what you want for the UI anyway. Unless you have a lot of players connected you shouldn’t worry about replicating some integers and references just be careful with replicating strings and Text.

Thanks for your answer, I was calling a RPC everytime a slot change (this mean multiple call very quickly if multiple Array Elems changed), but like you said it’s not viable for this…

How would you handle the update on client UI, if multiple Array Elems was changed on Server during a single frame? (to be the more data efficient)

I though about some systems :

1st : Using RepNotify

[OnServer] Array Slot Changed → Store Index in array → Call automatically OnRep_Function on client.

[OnClient] OnRep_Function → call a Server Event to gather the Indexes array → When the client receive the Indexes, update UI

2nd : Using RepNotify

[OnClient] OnRep_Function → Compare replicated array with the old one

3rd : Using simple Replication

[OnServer] Multiple Array Slots Changed in 1 frame → Store Indexes in array → Call Client_OnSlotsChanged(TArray Indexes)

[OnClient] Client_OnSlotsChanged → Wait for Ping Time (maybe not safe), to be “sure” the SlotsArray had enough time to replicate to the client → Update UI

What do you think?

Thank you, I know what setup to use now :slight_smile:

For people interested : Using twos arrays : Slots (Replicated), ChangedIndexes(RepNotify). OnRep_ChangedIndexes → Get changed Indexes → Get corresponding Slots → Update UI on client side