Time for action – Respect my authority!
Once again, back to AwesomeWeaponUpgrade
.
Let's change the
PostBeginPlay
function a bit:simulated function PostBeginPlay() { `log("PostBeginPlay===================="); if(Role == ROLE_Authority) `log("I am running on the server!"); else `log("I am running on the client!"); }
Compile the code.
Run the server and the client. Now let's take a look at what happens.
Run to the trigger, then take a look at the server's log:
[0014.57] ScriptLog: PostBeginPlay==================== [0014.57] ScriptLog: I am running on the server!
Now let's take a look at the client:
[0010.53] ScriptLog: PostBeginPlay==================== [0010.53] ScriptLog: I am running on the client!
What just happened?
This is useful when we want both the client and the server to run a function, but we want them to have different responses to that function. As an example, since particle effects don't need to be spawned on the server since they'd just waste processing...