Replicated Function
A replicated function is one that is called on one machine, but executed on a different one. It's a function call sent over network (from server to a client, for example, or from a client back to the server; it is not possible however to replicate a function from one client to another client).
Executing Replicated Functions
There's no difference between calling replicated and other functions. This usually means if you want to run (not: call) a replicated function on a client it has to be simulated and the actor's RemoteRole must be at least ROLE_SimulatedProxy. See simulated function for more details on this.
If you replicate a non-simulated function to a client it won't be executed at all. Functions replicated to the server don't need to be simulated since the simulated keyword only affects where a function may be executed, not where it can be called.
Replicating Function Calls
- Function calls can only be replicated to or from the client owning the actor
- If the client doesn't own the actor your log will output Received Unwanted Function
This means the Owner of the actor containing the replicated function must be a PlayerPawn in UT or a PlayerController or Pawn owned by a PlayerController in UT2003.
To actually replicate a function call from the server to a client you have to use a replication statement like the following:
replication { reliable if ( Role == ROLE_Authority ) FunctionName; }
This will replicate function calls for FunctionName to the client this actor belongs to. If the actor is either owned by the server's player or Owner is None the function will be executed on the server like a regular function.
To replicate a function call from a client to the server you have to use a replication statement like the following:
replication { reliable if ( Role < ROLE_Authority ) FunctionName; }
This replicated function calls for FunctionName to the server if the actor is owned by this client's player.
Reliable vs. Unreliable Replication
Function calls will always reach the other side if the connection is free of errors. Unreliably replicated function calls can be lost due to packetloss, though.
What Gets Replicated?
When a function call is replicated all the parameters are replicated as well. The usual pitfalls apply, i.e. replicated actor references are only valid if the actor actually exists on the client, basic variable types, enums and structs will be replicated, while dynamic arrays won't. Of course you can only access other actors if they actually exist, i.e. if you are on the server or the actor is relevant to the client. If you pass a client-side actor as the parameter of a function replicated to the server, this parameter will be None on the server for obvious reasons.
If a replicated function has a return value it will return a null value (False, 0, "", None, etc.) whenever the function is really replicated to a different computer.