What i should replicate?

Hi, i’m confused about network replication.
What I realized is that if a variable is replicated, it is synchronized between the server and the client.
Now for example i’ve start to make an inventory system that have an array which contain structs stored as “Items”.
I should replicate the inventory the array or both?

At my current point i’m frustrated because if i run some function “OnServer” i cant see any changes on clients.
If i run in “multicast” variables isn’t synchronized.

There some guidelines to follow? If screen is needed i can post it

Screen is not needed so much as a better explanation of what you are actually trying to accomplish. Replication is one of those things that will vary dramatically between games and implementations. For example, if you are making an RPG and you have a stat system, you might replicate the player stat integers, but not the names, choosing instead to store the names locally so that there is less traffic over the network.

Their is a very good tutorial on the Unreal Engine Youtube channel that talks a great deal about the ins and outs of replication, including which types are best to use in which scenarios.

Thanks RAVaught. For example, a multiplayer chat. I have a gamestate class that store an array of strings. With UMG when i type something, this will be added to the array in gamestate and propagated to all clients. So:

Client 1 > Server > Client1, Client2, Client3, Client5…

What i’ve achivied is only the server part (when i type somethings from server window). The function is replied to clients. But if i type from client, the function it’s not propagated.

This is my setup Of UMG

Ok, I see a couple of things here, most of which are hard to tell from a single screen shot, so let me ask you a few questions and see where it gets us.

  1. Where is the event Client Add Entry being called? I see the client bind event, but not the event call to client add entry. This stands out as uniquely different from your server code, which has the event call but no event bind.
  2. Where are there variables that you are trying to replicate? You have precisely 0 variables in this graph. Obviously, you don’t want to pass an array of strings every time, just the string as a parameter, so I see no need to actually replicate anything in this instance. If you replicated the array of strings, it would try and pass the entire array at every update (I think) which could quickly consume a lot of bandwidth.
  3. Why aren’t you using a Switch has Authority? Ideally, you would use a Switch Has Authority node after the Switch on ETextCommit. The server branch would update the StateMachine and the remote branch would update the local users window. Not only would this prevent a potential vulnerability, but it would also give you an entry point for any other types of checks you wanted to do.
  4. (Not A Question, but a suggestion) I’ve found CastTo nodes to be rather problematic. I would create an Interface Blueprint that is implemented by your game state object, and call the interface message instead of using the cast.

Hope this helps,
Tony

1 Like