AActor::SwapRoles
#include "GameFramework/Actor.h"
Access: public
Specifiers: ENGINE_API
Description
Swaps the values of Role and RemoteRole on this actor. Used internally by the replication system when adjusting authority perspective.
Caveats & Gotchas
- • The comment in the header reads: "Only call this if you know what you're doing!" Incorrect use can make HasAuthority() return the wrong value, breaking replication logic throughout the actor.
- • This is called automatically by ExchangeNetRoles during initial replication setup — you almost never need to call it manually in game code.
- • After calling SwapRoles, any code path that checks Role == ROLE_Authority will now behave as if this machine is the server, which can lead to double-authoritative bugs in listen-server setups.
Signature
ENGINE_API void SwapRoles(); Return Type
void Example
Understanding when the engine calls this internally C++
// The engine calls ExchangeNetRoles, which calls SwapRoles internally,
// when an actor arrives on the client for the first time.
// You rarely need to call SwapRoles directly.
// If you must, always restore symmetry:
void AMyActor::TemporaryAuthorityCheck()
{
SwapRoles(); // Now HasAuthority() returns true
// ... authority-dependent logic ...
SwapRoles(); // Restore original roles
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?