In this lesson, you will learn how to distinguish between ROLE_Authority and ROLE_AutonomousProxy to determine which machine is responsible for defining the "truth" of an actor’s state.
In Unreal Engine’s client-server architecture, every networked actor holds a Role property that dictates its level of control. Understanding these roles is the foundation of preventing state desyncs and cheating.
Authority vs. Proxy
- ROLE_Authority: The machine that has absolute control over the actor's state. On a dedicated server, this is always the server. If a machine has
ROLE_Authority, any changes it makes to replicated variables are automatically pushed out to all connected clients. - ROLE_AutonomousProxy: This is a special role assigned to a client that "owns" a specific actor—usually the player character they are controlling. While the client doesn't have the final say, it is given the privilege to predict movement and send input to the server, which the server then validates.
Identifying Roles in Code
You can check a machine's role at any time using the GetLocalRole() function. This is vital when writing logic that should only execute on the governing machine:
void AMyCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (GetLocalRole() == ROLE_Authority)
{
// Only the server runs this logic (e.g., updating health, awarding XP)
ApplyGameLogic();
}
else if (GetLocalRole() == ROLE_AutonomousProxy)
{
// This machine is the player; run local-only responsiveness like UI triggers
UpdateHUDForLocalPlayer();
}
}
If you attempt to modify a server-side variable (like Health) from a ROLE_SimulatedProxy (a client looking at someone else's character), the server will ignore or override your change, as that client lacks the authority to set the state. The server is the final arbiter of truth; the AutonomousProxy is merely an empowered participant allowed to suggest state changes that the server must eventually confirm.
Key Takeaway: The server acts as the absolute Authority for all game states, while the AutonomousProxy allows the owning client to predict local actions to ensure the game feels responsive.