4: Unreal Engine Network Architecture: Technical Essentials Summary

Source: Internet
Author: User

Replication Essentials

1.simulated function in a network environment only exec,client, the simulated function is called on the client. If a function does not have any prefixes, it will only be called in the server. In addition, for a simulated function, he is either called by another simulated function or is called in the native function to execute on the client.   Application ExamplesSimulated function PostBeginPlay () {' Log ("PostBeginPlay"); Numberone ();
} simulated function Numberone () {' Log ' ("Number One"); Numbertwo ();
} function Numbertwo () {' Log ("number"); Numberthree ();
} SIMULATEDF function Numberthree () {' Log ("number three");} server-side run results:Postbeginplaynumberonenumbertwonumberthree operation result of client side:Postbeginplaynumberone Conclusion: since Numbertwo () does not have a simulated prefix, we conclude in the front that any function without a prefix modifier will only be invoked on the server side.   because of the need to save bandwidth, we can keep the same running code as the client and the server side, so it is possible to use simulated for this kind of work.   but we cannot write all of the functions as simulated because the client cannot access all the actors. (for example, some generators spawner Actor, even if they hit log in their simulated postbeginplay there is no output)   2. What runs on the server and which is running on the client side we know that the non-simulated function is definitely no longer running on the client, but when we are in the simulated function we also want to have permission to set up some code snippets that we don't want to run in the client. Also, how do we know that our current game is completely running in the network environment.   role and RemoteroleIn the actor there is an enumeration type Enetrole, which defines how the server and the client treat this actorrole_nonerole_simulatedproxyrole_autonomousproxyrole_authority  var enetrole role,remoterole; By default, the server-side role=role_authority.  This is because, on the server side, the server needs to maintain all actors in the world, so he has control over all actors. Remoterole sets how we treat this actor on the client. For example, in the following Remoterole several property settings: Role_none: This actor will never be copied to the client. For example, Gameinfo is always running in the server, its remoterole=role_none, actorfactor in the game or spawner can be set, because you do not need the client to have this content. Role_simulatedproxy: Basically all actors that need to be copied are this attribute, such as Projectile,vehicle, where all clients need to predict their physical and other behavior of the actor. Role_autonomousproxy: Only used in two places, one is the client's own pawn, namely the player pawn, the other is demorecspectators extends Utplayercontroller.  This property is close to Role_simulatedproxy, except that they are not limited to simulated role_authority:remoterole can not be used, which indicates that the actor is either on the server side or a single player game. Run the following code simulated function PostBeginPlay () {' Log ("PostBeginPlay"); ' Log ("role=" @Role); ' Log ("Remoterole" @RemoteRole) ;
The result on the server side: postbeginplayrole=role_authority; Remoterole=role_simulatedproxy; Results on the client: Postbeginplayrole=role_simulatedproxyremoterole=role_authority is exactly the opposite result, which is why?  Server side as we expected, but for the client the exact opposite, we re-do an experiment. Simulated function Postbeignplay () {' Log ("PostBeginPlay"), if (role==role_authority) ' Log ("I ' M on Server"); Else ' Log ("I ' m on Client ');
} on server side I ' m on server at the client if I ' m on server is running on server side, actor role for role_authority in the client actor role is Role_ Simulatedproxy According to this feature, we can delimit some functions to run in a particular port environment, such as a splash example does not need to run on the server side, so only need to judge the current Role<role_authoriy, If it is not, it is running in the client.      if (role<role_authority) Spawn (particle); Splash blood Sometimes there are some gameplay code that just needs to be on the server side and we can do it in reverse. 3. Whether running in the network environment Netmode There is an enumeration in Worldinfo EnetmodeNm_standalone,//standalone operation: No server nm_dedicatedserver,//reconnaissance server: Running on one server, other clients connected to the past. Mmonm_listenserver,//Listener server: A local client hosted as a server, host Game, other players connected, instead of the remote machine.  Nm_client//client: Connect to the server as a client. Because it is in worldinfo, we can delimit and query the level netmodesimulated function PostBeginPlay () {' Log ("Netmode:" @WorldInfo. Netmode);} For server-side netmode:nm_dedicatedserver for client netmode:nm_client Why do you need to netmode this enumeration to differentiate if you have role? Because Netmode on the server side there are two kinds: nm_dedicatedserver or nm_listenserver, and for role on the server side is always role_authority then when to use Netmode? Said before the blood particles in the server to play, but for the nm_listenserver server, like CS in the player host (in fact, the client is doing Hostgame host), of course, also to play the blood particles, so you can use the Nm_listenserver to make a difference.       4.Replication Variable Copy variable replication is reliable in any state. Except for array variable replication. A static array can be copied, and a dynamic array cannot. Unless you pass each of its individual values to an intermediate variable, it is best not to. Do an example: Var int testnum; replication{if (bnetdirty) testnum;
} simulated function PostBeginPlay () {if (role=authority)//execute SetTimer on server side (1,true, ' servertest '); else//execute SetTimer (1,true, ' clienttest ') on the client;
} function Servertest () {testnum++; ' Log ("Server:" @TestNum);
} function Clienttest () {' Log ("Client:" @TestNum);
Result Analysis: The server-side tour server:1server:2server:3 ... On the client side there are client:1client:2client:3 ... Because the server side is constantly changing, bnetdirty==true will always pass the value to the client Some keywords for variable replication: netpriority:Priority, pay attention to increasing the priority of this variable, replication can take precedence over other variables, but cannot make it faster to copy, because there are other actor precedence. Bnetdirty:The value of the variable has changed. bnetinitial:True if all of the variables are initialized for replication to complete. Bnetowner:True if local Playercontroller owns this variable balwaysrelevant:If true, this variable will be updated for all the client. Note that some situations, such as when other players simply do not see what the variable is related to, should not be true to conserve bandwidth. Breplicateinstigator:If the variable has a instigator, copy it to clients, for example, pawn that the actor is causing damage. breplicatemovement:Copy position and motion variables, such as velocity. bskipactorpropertyreplication:Do not copy any attributes of this actor   netupdatefrequency:Update the frequency of replication, the lower the value priority is lower if (!bskipactorpropertyreplication | | bnetinitial) && (role==role_authority) && Bnetdirty && breplicateinstigator) instigator; Reading it, this tells us so if we ' re not skipping property replication or we ' re still initializing,and we ' re the server , and a replicated property had changed, and we want to replicate Theinstigator, then replicate the instigator variable. These replication statements can seemconfusing at first, but examining what each variable does and taking a look at other Examplesin the source code would give you a understanding of when they should be used. 5.ReplicateEventThe modifier is repnotify before some variables, which causes relicateevent to be called when the variable is replicate. Example: The result is on the server side: servertest:1 on client: This replicated Event is working 6. Some settings for actor the advent of the general network actorIf the actor is displayed only on the server and does not exist on the client, set its actor attribute Remoterole=role_simulatedproxy//tells the client how to treat the actor, most of the Projectil E and vehicle, can be crushed box can be set balwaysrelevant=true//This can also be set with distance to save bandwidth Remoterole=role_ Simulatedproxy-tells the game's client how to handle the actor, meaning: This client has a local copy of the server copied to represent the actor. Balwaysrelevant=true for players This is related get local PlayercontrollerGetalocalplayercontroller () and foreach localplayercontrollers are permanently invalidated, so you must use other traversal methods such as dynamicactors, etc. 7.GameReplicationInfoGameinfo does not exist on the client side, so we created Gamereplicationinfo to pass the information in Gameinfo to the client side in Defaultproperties of Gameinfo defaultproperties{gamereplicationinfoclass=class ' Artgamereplicationinfo '
Here's an example: if there are some variables in gameinfo that need to be known by the player, such as how many enemies var int enemynumleft are in the current scene; There are Artgamereplicationinfo (Artgamereplicationinfo) in the Artgame. Enemynumleft=enemynumleft; then var int enemynumleft in class artgamereplication; replication{if (bnetdirty) enemynumleft;
}   In the same way, most of the data in Playercontroller and pawn we can move to Artplayerreplicationinfo to handle HUD displays, such as the player's current experience and level       8. Modifiers on function Reliabale VS Unreliable   Reliableis always reliably transmitted, based on the TCP transport mode, which eventually arrives at the destination in a resend manner even in the event of a bad network environment. unreliableBased on UDP, although the efficiency is high, but it is possible to lose the transmission, some unimportant implementation can be used in this way, such as blood spatter.   client function:When the server wants to raise a function on the client, this function will never be executed on the server side but only on the client. For example, there is a givepawn function in Playercontroller, which is responsible for setting a pawn to the client, and the server side does not care, just say to the client: "Hey, this is your responsibility, hurry to deal with it!" ”。 Reliable client function Givepawn (Pawn newpawn) does an example: Unreliable client function playteleporteffect () {//Play a transfer effect on the client Child
The client function is, of course, executed only by the actor-owned actors, and what actor is usually owned by this customer? Typically, such as Playercontroller,pawn,weapon,inventory,playerreplicationinfo are owned by this client most actors placed in the scene are not owned by the client, and Spawner are often not owned by the client.   Make an example:Place an actor in the scene, and then call////function in the client postbeginplay only reliable clients functions Clientcall () {' Log ("client function called by the Server "); The log is not seen on both the server side and the client. It will appear in the Artpawn and Artplayercontroller clients. Server function:Server Funcionn is a call from the client to help me, for example the client will say: "I'm going to perform an action and you have to make sure you respond to the event on the server side." "For example, an EXEC function is executed only on the local client, and the server side does not have the corresponding action, this time to be notified." Perform an instance: Exec function use () {' Log ("I ' m using the trigger!");
Running on the client will execute log, but the server side will not act.    Only exec function use () {' Log ("I ' m using the trigger!") is required at this time; Serveruse ();
} Reliable Server function Serveruse () {' Log ("server using the trigger");
At this time the server side will perform the corresponding action and the client will not server-side output: Server using the trigger of course we can also pass parameters to the server side on the client: Reliable server function serveruse (int Num {' Log ' ("Server using the Trigger:" @num);
The EXEC function use () {' Log ("I ' m using the trigger!") in use ();  Serveruse (3); The server using the trigger 3 will be output at the end.  

4: Unreal Engine Network Architecture: Technical Essentials Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.