I love the smell of UnrealEd crashing in the morning. – tarquin

Legacy:Another Look At Replication

From Unreal Wiki, The Unreal Engine Documentation Site
Revision as of 17:33, 7 January 2016 by *mGm*Lizard (Talk | contribs) (I only asked a question.)

Jump to: navigation, search

The Meaning Of The Replication Block

replication
{
         reliable if( Role == ROLE_Authority )
           somevar;
         reliable if( Role < ROLE_Authority )
            someInputVar;
}

The first part of the replication block here is saying, if 'somevar' changes on the server, then the server should tell others about it.

The second part says if 'someInputVar' changes on the client, then the client will send that data back to the server.

When writing your replication statements, your conditional check is a specification of who should be SENDING the data, and then that data will be sent to everyone applicable.

I'm guessing this means that the server will always send to the owner of the actor, and maybe even ALL clients.

On the other hand, Clients can ONLY send data to the server.

MtTracer: As far as I know variables are not necessarily sent directly after they changed. Replication happens frequently but you can't tell when exactly. Only bNetDirty can be used to see if at least one property of this a class has been changed since the last replication check. Second, the server will allways send its variables to every "copy" of this actor on all clients except you used bNetOwner in the condition check.

replication
{
reliable if( ROLE == ROLE_Authority )
   ServerVersionOfSomeImportantValueTheClientIsGoingToChange;
reliable if( ROLE < ROLE_Authority )
   NotifyServer, SomeImportantValueTheClientIsGoingToChange;
}
 
simulated function MyClientSideFunc()
{
SomeImportantValueTheClientIsGoingToChange++;
NotifyServer();
}
 
function NotifyServer()
{
    if( SomeImportantValueTheClientIsGoingToChange == NOT_A_PROBLEMATIC_CHANGE )
       ServerVersionOfSomeIMportantValueTheClientIsGoingToChange=SomeImportantValueTheClientIsGoingToChange;
}
 
simulated event DrawHUD(Canvas C)
{
   C.DrawText("Client Value specified is: "@ServerVersionOfSomeImportantValueTheClientIsGoingToChange);
}

Now what's going on here, is that the client is going to change SomeIMportantValueTheClientIsGoingToChange, and call NotifyServer.

This call to notify server is going to be called on the ServerMachine, both because it's non-simulated, so it can't execute on the client, and because we are replicating this function from the client to the server.

in NotifyServer The server will allow the change and set it's version of this variable, 'SeverVersionOfSomeIMportantValueTheClientIsGoingToChange' to the client variables value.

Now that this has happened, the drawhud function is going to draw the value of the server's version of the variable to the clients hud during updates.

This is simply an example to get the point across. Specifically, i have not tested to see whether SomeImportantValueTheClientIsGoingToChange will take it's new, client modified value, before NotifyServer is called and the value is assigned.

This understanding has fixed some of my recent problems so i hope it helps you too.

Comments

Tarquin: Perhaps this can be folded into Introduction To Replication?

Solid Snake: Fixed a spelling mistake for those who cut-copy code from places, and also it may be better to just use A, B instead of really long labels for the sake of readability?

Mychaeel: Especially for sake of readability I'm particularly fond of well-crafted, long symbol names... though I have to admit that the ones used here aren't terribly well-crafted. They're just a string of WordsSmashedTogetherLikeSo.

Sweavo: Agree that this should be folded-in, also that human-meaningful names are better than A and B

*mGm*Lizard: Does this page apply to UT2004?


Category:Legacy To Do – This needs merged into the grand topic of Replication. See Replication/Discussing