AActor::HasAuthority
#include "GameFramework/Actor.h"
Access: public
Specifiers: const
Description
Returns true if this actor is running on the authoritative (server) instance. Equivalent to checking `GetLocalRole() == ROLE_Authority`. Essential for gating server-only logic in multiplayer games.
Signature
bool HasAuthority() const Return Type
bool Caveats & Gotchas
- • In a listen server game, the server host also acts as a client — HasAuthority() still returns true on the server.
- • In single-player, HasAuthority() always returns true.
- • Do not confuse with `IsLocallyControlled()` which checks if the local machine controls this actor.
Example
Server-only logic C++
void AMyActor::HandleDamage(float Damage)
{
if (!HasAuthority()) return; // Only process damage on the server
Health -= Damage;
if (Health <= 0.f)
{
Destroy();
}
} Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?