Role and authority
We know that non-simulated functions don't run on clients. But when we're in a simulated function, how do we tell the server and the client apart? For that matter, how do we know we're running the game in a network environment at all? There are a few variables we can use to help us out. The first, and most important, are Role
and RemoteRole
.
Role and RemoteRole
These two variables are declared in Actor
as an enum and tell the game how the server and client should treat this actor. Let's take a look at the list:
enum ENetRole { ROLE_None, // No role at all. ROLE_SimulatedProxy, // Locally simulated proxy of this actor. ROLE_AutonomousProxy, // Locally autonomous proxy of this actor. ROLE_Authority, // Authoritative control over the actor. }; var ENetRole RemoteRole, Role;
By default, Role
will always be ROLE_Authority
on the server. This makes sense, since the server needs to have the last word on the state of all actors in the game. While...