Understanding Server-Client

I have this confusion about how the blueprint is run on server and client that I wanted to clear up. Lets say all the players are using the same player character BP, and in the player character BP, I have an event that is run on server which increments an int variable. When the client calls this event, the event is actually being run on the server’s version of the player character but changing the variable of the client right? So the server’s version of the variable in the player character does not change when clients run the event right? Just had this confusion for awhile and wanted to get it straight once and for all, thanks for any help! :slight_smile:

Edit: A current issue I’m facing is that I’m using an event that is run on server to separate my player controllers into two teams, team true and team false. So what happens is on begin play, it would call this run on server function which would get “self” to figure out what team it is in to append into the appropriate array. But when the event is called from a client and running on the server, would “self” refer to the owning client that called the event, or would it be referring to the server?

Hi,

When the client calls this event, the
event is actually being run on the
server’s version of the player
character

If the event is not set to RunOnServer, then it runs locally on the client on the client version of the player character and the server will never know about it.

If you would use The RPC (RemoteProcedureCalls) RunOnServer then the client would ask the server to run this event on the server but the client will only know about the increment of the int if you have set this variable to Replicate or RepNotify.

So the server’s version of the
variable in the player character does
not change when clients run the event
right?

I think you misunderstand something or I don’t understand the question :slight_smile:
Imagine you have one server and three clients and they all possess a player character BP. Then there will be four different player character BP on the server and on each client. If the server runs something locally or a client runs something locally then all the other won’t know about this.

Everything that is set to Replicate/RepNotify will be replicated from the server to the clients. If the server “thinks” that a variable (that is set to Replicate/RepNotify) on a client version differs from the server version, then the server will send an update to that client.

So if the client would call RunOnServer on the pawn he possesses, then this will run on the server version of the pawn this client possesses and not on the server version of the pawn the server possesses.


would “self” refer to the owning
client that called the event, or would
it be referring to the server?

If the server executes this, self would refer to the server version of the player controller. If the client executes this self would refer to the client version of the player controller.

Thanks, that clarified the misconception I had :slight_smile: