LogoLogo
⚠️ Outdated documentationGo to LatestHomeAPI
SDK 0.9
SDK 0.9
  • Welcome
  • Overview
    • What is coherence?
    • How does coherence work?
    • Features and Roadmap
    • Rooms and Worlds
    • Requirements
    • Release Notes
  • Get Started
    • Install coherence
    • Scene setup
    • Prefab setup
    • Baking and code generation
    • Build and run
    • Create a free account
    • Deploy Replication Server
    • Share builds
    • Troubleshooting
  • Authority and communication
    • How authority works
    • Authority transfer
    • Commands
    • Simulation frame
    • Client connections
    • Server-authoritative setup
    • GGPO
    • Animations
    • Value sync callbacks
  • Persistence
    • Overview
    • Configuring persistence
    • Storage
    • Example – a global counter
  • Optimization
    • Overview
    • Simulation frequency
    • Areas of interest
    • Level of detail
    • Interpolation
  • Connected entities
    • Overview
    • Entity references
    • Parent-child relationships
    • CoherenceNode
  • Simulators
    • Overview
    • Client vs Simulator logic
    • Build and deploy
    • Simulator load balancing
    • Room Simulators
    • Multi-Room Simulators (advanced)
    • World Simulators
    • Simulator slugs
    • Testing Simulators locally
  • 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. Team-based
      • 8. Connected Entities
  • Game Services
    • Game account
    • Key-value store
    • Matchmaking
  • Developer Portal
    • Overview
    • Dashboard
    • Enabling game services
    • Configure Rooms
    • Manage Worlds
  • API reference
    • coherence SDK
      • CoherenceSync
      • MonoBridge
      • LiveQuery
      • Level of detail
      • Sample UI
      • Settings window
      • Custom bindings (advanced)
      • PlayResolver
      • Rooms
      • Worlds
    • Cloud API
      • API tokens and keys
      • Game account
      • Key-value store
      • Matchmaking
    • Replication Server
    • Simulation Server
  • Schema reference
    • Overview
    • Specification
    • Field settings
    • Archetypes in schemas
  • Resources
    • Downloads
    • SDK update guide
    • Video tutorials
    • Order of execution
    • Glossary
    • CLI utilities
    • Simulator CLI arguments
    • Helper scripts
    • Troubleshooting
    • Continuous Integration setup
  • Community
    • Community
  • Additional information
    • Pricing
    • SLA
    • Unreal Engine support
    • WebGL
    • Peer-to-Peer (P2P)
Powered by GitBook
On this page
  • Rooms API
  • Worlds API

Was this helpful?

Export as PDF
  1. API reference
  2. coherence SDK

PlayResolver

Last updated 2 years ago

Was this helpful?

The PlayResolver encapsulates all the internals to fetch and join both Rooms and Worlds.

using Coherence.Runtime;

// ensure connection to the play services backend
async Task<bool> PlayResolver.EnsurePlayConnection();

Rooms API

Detailed usage can be found under chapter .

// Returns true if there is a valid local server running.
// Returns "local" as the region if local server is running.
async Task<(bool, string)> FetchLocalRegions()

// Returns all the regions where rooms are enabled in the portal.
async Task<IReadOnlyList<string>> FetchRegions()

// Fetch a list of rooms currently active in the given region.
// Optionally, filter by tags provided when creating the room.
async Task<IReadOnlyList<RoomData>> FetchRooms(string region, string[] tags = null)

// Create a new room in the region. 
async Task<RoomData> CreateRoom(string region, RoomCreationOptions options = null)

// Convert RoomData to EndpointData, to call IClient.Connect(endpoint) directly.
// The second return value is false if the room data is invalid. 
(EndpointData, bool) GetRoomEndpointData(RoomData room)

Example usage for Rooms API:

using UnityEngine;
using Coherence.Runtime;
using Coherence.Toolkit;

public class CreatorAndJoiner : MonoBehaviour
{
    private CoherenceMonoBridge bridge;

    private async void Start()
    {
        if (!MonoBridgeStore.TryGetBridge(gameObject.scene, out bridge))
        {
            return; 
        }
        
        // XXX: try-catch everything
        var regions = await PlayResolver.FetchRegions();
        var rooms = await PlayResolver.FetchRooms(regions[0]);

        
        if (rooms.Count == 0)
        {
            var room = await PlayResolver.CreateRoom(regions[0]);
            bridge.JoinRoom(room);
        }
        else
        {
            bridge.JoinRoom(rooms[0]);  
        }
    }
}

Worlds API

// Returns true if a local worlds replication server is running.
async Task<bool> EnsureLocalServer()

// Fetches the connection data for local replication server.
async Task<WorldData> FetchLocalWorld()

// Fetches a list of worlds from the portal.
async Task<IReadOnlyList<WorldData>> FetchWorlds()

// Convert WorldData into EndpointData, to call IClient.Connect(endpoint) directly.
// The second return value is false if the world data is invalid. 
(EndpointData, bool) GetWorldEndpoint(WorldData world)

Example usage for Worlds API:

using UnityEngine;
using Coherence.Runtime;
using Coherence.Toolkit;

public class WorldJoiner : MonoBehaviour
{
    private async void Start()
    {
        if (!MonoBridgeStore.TryGetBridge(gameObject.scene, out var bridge))
        {
            return; 
        }
        
        // XXX: try-catch everything
        var worlds = await PlayResolver.FetchWorlds();
        if (worlds.Count > 0)
        {
            bridge.JoinWorld(worlds[0]);
        }
    }
}

Detailed usage can be found under chapter .

Rooms
Worlds