Mirror
  • Mirror Networking
  • API Reference
  • Development Blog
    • A Brief History of Mirror
  • User Manual
    • General
      • Getting Started
      • Script Templates
      • Change Log
        • 2024 Change Log
        • 2023 Change Log
        • 2022 Change Log
        • 2021 Change Log
        • 2020 Change Log
        • 2019 Change Log
      • Deprecations
      • Migration Guide
      • Integrations
      • Timestamp Batching
      • TCP and UDP
      • CCU
      • SyncDirection
      • Round Trip Time (RTT)
      • Connection Quality
      • Lag Compensation
      • Client Side Prediction
      • History Bounds
      • Tests
      • NetGraph
    • FAQ
      • Execution Order
    • Transports
      • KCP Transport
      • Telepathy Transport
      • WebSockets Transport
        • Reverse Proxy
          • Windows
            • IIS
          • Linux
            • NGINX
            • Caddy
            • Apache
            • HA Proxy
        • SSL
      • Multiplex Transport
      • Latency Simulation Transport
      • Ignorance
      • LiteNetLib Transport
      • FizzySteamworks Transport
      • FizzyFacepunch Transport
      • Encryption Transport
      • Edgegap Transports
        • Edgegap Relay
        • Edgegap Lobby
    • Components
      • Network Animator
      • Network Authenticators
        • Basic Authenticator
        • Device Authenticator
      • Network Behaviour
      • Network Discovery
      • Network Identity
      • Network Manager
      • Network Manager HUD
      • Network Ping Display
      • Network Profiler
      • Network Rigidbody
      • Network Lerp Rigidbody
      • Network Room Manager
      • Network Room Player
      • Network Start Position
      • Network Statistics
      • Remote Statistics
      • Network Transform
        • Snapshot Interpolation
      • Deprecated
        • Network Proximity Checker
        • Network Scene Checker
        • Network Match Checker
        • Network Owner Checker
    • Interest Management
      • Spatial Hashing
      • Distance
      • Scene
      • Scene + Distance
      • Match
      • Team
      • Custom
      • Legacy
    • Guides
      • Authority
      • IDs
      • Attributes
      • Time Synchronization
      • Data types
      • Serialization
      • Synchronization
        • SyncVars
        • SyncVar Hooks
        • SyncEvent (Obsolete)
        • SyncLists
        • SyncDictionary
        • SyncHashSet
        • SyncSortedSet
      • Communications
        • Remote Actions
        • NetworkManager Callbacks
        • NetworkBehaviour Callbacks
        • Network Messages
      • GameObjects
        • Player Game Objects
        • Custom Character Spawning
        • Custom Spawn Functions
        • Scene GameObjects
        • Pickups, Drops, and Child Objects
    • Examples
      • Additive Levels
      • Additive Scenes
      • Basic
      • Billiards
      • Multiple Additive Scenes
      • Pong
      • Room
      • Tanks
      • EdgegapLobby
  • Server Hosting
    • The Pragmatic Hosting Guide
    • Cloud Hosting Guides
      • AWS
      • Google Cloud
      • Oracle Free Tier
    • Hosting with a Remote Desktop
    • Edgegap Hosting Plugin Guide
  • Security
    • Security Overview
    • Cheat Protection Stages
    • Cheats & Anticheats
  • Community Guides
    • Community Translations
    • Video Tutorials
    • Resources
    • Mirror Quick Start Project
    • Unity for MMORPGs
    • Unity Canvas HUD
    • Odin Inspector Support
    • Ready Up And Die!
    • iOS AppStore
    • Mirror Docker Guide
    • Gitbook Guide
    • Mirror Branding
    • Contributors Agreement
    • Documentation License
Powered by GitBook
On this page
  • Network Authority
  • Server Authority
  • Client Authority
  • How to give authority
  • How to remove authority
  • On Authority
  • Check Authority
  1. User Manual
  2. Guides

Authority

PreviousGuidesNextIDs

Last updated 11 months ago

Network Authority

Authority is a way of deciding who owns an object and has control over it.

Server Authority

Server authority means that the server has control of an object. Server has authority over an object by default. This means the server would manage and control the collectible items, moving platforms, NPCs, and any other networked objects that aren't the player.

Client Authority

Client authority means that the client has control of an object.

When a client has authority over an object it means that they can call and that the object will automatically be destroyed when the client disconnects.

Even if a client has authority over an object the server still controls SyncVar and control other serialization features. A component will need to use a to update the state on the server in order for it to sync to other clients.

How to give authority

By default, the server has Authority over all objects. The server can give authority to objects that a client needs to control, like the player object.

If you spawn a player object using NetworkServer.AddPlayerForConnection then it will automatically be given authority.

Using NetworkServer.Spawn

You can give authority to a client when an object is spawned. This is done by passing in the connection to the spawn message

GameObject go = Instantiate(prefab);
NetworkServer.Spawn(go, connectionToClient);

Note: A change of NetworkServer.Spawn hierarchy is not automatically synced.

Using identity.AssignClientAuthority

You can give authority to a client any time using AssignClientAuthority. This can be done by calling AssignClientAuthority on the object you want to give authority to.

identity.AssignClientAuthority(conn);

You may want to do this when a player picks up an item

// Command on player object
void CmdPickupItem(NetworkIdentity item)
{
    item.AssignClientAuthority(connectionToClient); 
}

How to remove authority

You can use identity.RemoveClientAuthority to remove client authority from an object.

identity.RemoveClientAuthority();

Authority can't be removed from the player object. Instead, you will have to replace the player object using NetworkServer.ReplacePlayerForConnection.

On Authority

When authority is given to or removed from an object a message will be sent to that client to notify them. This will cause the OnStartAuthority or OnStopAuthority functions to be called.

Check Authority

Client Side

The identity.isOwned property can be used to check if the local player has authority over an object.

Server Side

The identity.connectionToClient property can be checked to see which client has authority over an object. If it is null then the server has authority.

Commands
Commands