Understanding replication in blueprints

Hi, this question pretty much refers to my question from yesterday: https://answers.unrealengine.com/questions/233981/use-replication-to-move-an-object.html
But I guess this is the key to solve it and it might be easier to have a look on it without the whole content of my project in the other question. But I will add a comment there refering to this.

To get started: I made a pretty simple level, looking like this:

I created a simple pawn (in fact it’s just a camera) that will do nothing but looking to the wall (and the Text) and recieving an input if the F-Key is pressed:

If the key is pressed the pawn causes an event running on the server that decrements the value that is displayed on the text render actor by 1. The value is set on “Replicated”. Now there is the part where i guess the failure might be located but I am not sure about that. My Gameinstance is storing a reference to a Text Render Actor (called “Text1”). In the LevelBlueprint I set this actor as the (only) Text Render Actor on the Map.

If i run this project (Press “Play” with 2 players as settings) the following happens: if I press “F” in the client’s window, everything is fine. In both windows the displayed number will decrement. If I press “F” in the server’s window, nothing happens. OK, that’s not true. I watched the values in the debug view. As you can see below, there are 4 Pawns I can watch


I guess this is OK, I got 1 Pawn for every Player in every window (so I got Player*Player Pawns in general). If I press F - no matter where - 2 of the Pawns (one in each window) will capture the decrementation, the other both stay. Why don’t the raplication cause them all to have the same value?
There is one other thing comming to my mind: To get started I followed the official Epic games blueprint network tutorial and there everything worked. If I watch values in the debug mode there, 2 of the Pawns got the same name:


maybe this is another thing that could lead to a solution. Thank you guys so much for reading, I hope you can help me :slight_smile:

You have 4 pawns. Name it, for example, like this:

 1. PawnS (original server) - server player
 2. Pawn1 (original server) - client1 player
 3. PawnS_RC (Replication Copy on client1)
 4. Pawn1_RC (Replication Copy on client 1)

Your action:

1. You play on client1 and possess pawn1 on server
 2. You press F, call event "F Input" inside Pawn1_RC. Pawn1_RC try to call 'Call Decrement' - server version. And this event called on Pawn1 (original server). Value was decreased inside server original instance of YourPawn class (Pawn1 in our list)
 3. Var "Count" inside Pawn1 changed, var "Count" inside other instance of class like "PawnS" still same.
 4. Pawn1 replicate its vars to their clients copy, so Pawn1_RC on client1 also change. PawnS_RC not change because its server original not change.

2 pawn changes, 2 - not. As expected.

What about Text? Dunno. Both pawn actially on every tick set Text value. And one of pawn have decreased value, while other - not. What value you see - i think its depend order of ticks.

I think server pawn spawn first, client1 spawn second (on connect). So they tick same order. Server tick first and set var with server value, then client1 tick second and overset var with client value. So you always see client value and never see server value.

Instead of level text you can add “Text component” inside pawn and set it. So you can see pawn value on each pawn independently

Ah, it makes sence that the client’s window only has copy’s. At least I understand this now. So the question should be: How can I make PawnS to take the new value if changed in Pawn1, too? I guess I have to get the value out of the Pawn and make it like global? How do I do this?

You can try create function like “SetSomeValueOnAllPawn(int32 value)” and change actial var on every pawn in list.

Forexample you can use Get All Actors of Class

find all yours pawn (on server) and change var inside every pawn you find.

If you change value inside every pawn on server - they all replicate values on every client copy they have.

About global vars - you can place var in “GameInstance” or “GameMode” (exist only on server) or “GameState” (exist both server and clients and can be replicated). So your “Call Decrement” function must use sequence like this - “GetGameState”->“Cast to MyGameState”->“Set Count”

Ok now I got it: I have to realize the whole global variable stuff with GameState and everything is fine. Thanks for answering, you helped me a lot to understand how it actually works.