LogoLogo
HomeOnline DashboardAPIDiscordForums
SDK 0.5.2
SDK 0.5.2
  • Welcome
  • Overview
    • What is coherence?
    • How does coherence work?
    • Features and Roadmap
    • Requirements
  • Get Started
    • Install coherence
    • Scene setup
    • Prefab setup
    • Build and run
    • Baking and code generation
    • Create a free account
    • Deploy replication server
    • Share builds
  • Authority and communication
    • How authority works
    • Authority transfer
    • Commands
    • Client messages
    • Server-side and input queues
    • Animations
  • Persistence
    • Overview
    • Configuring persistence
    • Storage
    • Example – A global counter
  • Optimization
    • Overview
    • Simulation frequency
    • Areas of interest
    • World size
    • Level of detail
    • Interpolation
    • Extrapolation
  • Connected entities
    • Overview
    • Entity references
    • Parent-child relationships
  • Simulators
    • Overview
    • Client vs. simulator logic
    • Build and deploy
    • Simulator load balancing
  • Tutorial project
    • Get the Tutorial Project
    • Start Tutorial
      • 1. Transforms
      • 2. Physics
      • 3. Persistence
      • 4. Animation and Variables
      • 5. AI Navigation
      • 6. Network Commands
      • 7. Network Teams (draft)
  • Game Services
    • Game account
    • Key-value store
    • Matchmaking
  • Developer Portal
    • Overview
    • Dashboard
    • Resource Usage
    • Replicator and Simulator Configuration
    • Enabling Game Services
  • API reference
    • Network SDK
      • CoherenceSync
      • MonoBridge
      • LiveQuery
      • Archetype
      • Sample UI
      • Settings Window
      • Custom Bindings
    • Cloud API
      • API tokens and keys
      • Server discovery
      • Game account
      • Key-value store
      • Matchmaking
    • Replication Server
    • Simulation Server
  • Schema reference
    • Overview
    • Specification
    • Field Settings
    • Archetypes and LOD-ing
  • Resources
    • Downloads
    • SDK Update Guide
    • Video Tutorials
    • Glossary
    • CLI Utilities
    • Helper Scripts
    • Troubleshooting
  • Community
    • Discord
  • Additional information
    • Pricing
    • SLA
    • Unreal Engine support
    • WebGL
    • Peer-to-Peer (P2P)
    • Known Issues
    • Changelog
Powered by GitBook
On this page
  • Overview
  • Types of Authority Transfer
  • Requesting Authority in Code

Was this helpful?

Export as PDF
  1. Authority and communication

Authority transfer

Last updated 3 years ago

Was this helpful?

Overview

The state of network entities that are currently not simulated locally (either because they are being simulated on another game client or on a simulator) cannot be affected directly.

Network can help us affect state indirectly, but for anything more involved, an authority transfer might be necessary.

Types of Authority Transfer

In the design phase, CoherenceSync objects can be configured to handle authority transfer in different ways:

  • Request. Authority transfer may be requested, but it may be rejected by the receiving party (i.e. when Approve requests is false).

  • Steal. Authority will always be given to the requesting party on a FCFS ("first come first serve") basis.

  • Not transferable. Authority cannot be transferred.

If you uncheck the Approve Requests, you can use the unity event OnAuthorityRequested to respond to the request.

The request can be approved or rejected in the callback.

public void OnRequest(ushort client)
{
    var coherenceSync = target.GetComponent<CoherenceSync>();
    // do some extra checks
    // transfer authority
    coherenceSync.TransferAuthority(client);
    
    // or reject authority request
    // coherenceSync.RejectAuthorityRequest(client);
}

Requesting Authority in Code

Requesting authority is very straight-forward.

var coherenceSync = target.GetComponent<CoherenceSync>();
coherenceSync.RequestAuthority();

As the transfer is asynchronous, we have to subscribe to one or more Unity Events in CoherenceSync to learn the result.

The request will first go to the replication server and be passed onto the receiving simulator or game client, so it may take a few frames to get a response.

// There Unity Events in CoherenceSync help us understand 
// what happened with authority requests and act accordingly.

// called when the CoherenceSync entity becomes the simulation authority
public UnityEvent OnAuthorityGained;

// called when the CoherenceSync entity loses simulation authority
public UnityEvent OnAuthorityLost;

// called when a request to assume authority over the CoherenceSync entity
// is rejected
public UnityEvent OnAuthorityTransferRejected;

These events are also exposed to the Unity inspector in the Events on authority transfer section of the CoherenceSync behaviour.

commands
Authority events in the CoherenceSync inspector