LogoLogo
HomeOnline DashboardAPIDiscordForums
SDK 1.7 Preview
SDK 1.7 Preview
  • Welcome
  • Overview
    • Features
    • Roadmap
  • Getting started
    • Get the Unity SDK
    • Setup a project
      • 1. Scene setup
      • 2. Prefab setup
      • 3. Test your game locally
        • Local testing using builds
        • Local testing via Unity's Multiplayer Play Mode
        • Local testing via ParrelSync
      • 4. Test in the cloud
        • Deploy a Replication Server
        • Share builds
    • How to... ?
    • Single-player to multiplayer
    • Video tutorials
    • Samples and tutorials
      • Package samples
      • Sample Connection UIs
      • First Steps tutorial
        • 1. Basic syncing
          • 1.1 Animation parameters
          • 1.2 Sending commands
        • 2. Physics / Authority transfer
        • 3. Areas of interest
        • 4. Parenting entities
        • 5. Complex hierarchies
        • 6. Persistence
      • Campfire project
        • Game mechanics
        • Leveraging object pooling
        • Remote interactions: Chairs
        • Remote interactions: Trees
        • A unique object with complex state
        • Custom instantiation and destruction
        • Running a server-side NPC
        • Playing audio and particles
        • A simple text chat
      • Beginner's guide to networking
    • Troubleshooting
  • Manual
    • Unity Components
      • CoherenceSync
      • CoherenceBridge
      • CoherenceLiveQuery
      • CoherenceTagQuery
      • CoherenceGlobalQuery
      • CoherenceInput
      • CoherenceNode
      • PrefabSyncGroup
      • Order of execution
    • Networking state changes
      • Instantiate and Destroy Objects
      • Supported types
      • Messaging with Commands
      • Syncing child GameObjects
      • Animation
      • CoherenceSync references
      • [Sync] and [Command] Attributes
      • [OnValueSynced] Attribute
      • Creating your own syncable member
      • Custom Component Actions
      • Rigid Bodies
      • Interpolation
    • Authority
      • Authority transfer
      • Server-authoritative setup
    • Lifetime
      • Persistence
      • Uniqueness
      • Example: A global counter
    • Parenting network entities
      • Direct children CoherenceSyncs
      • Deeply-nested CoherenceSyncs
      • Nesting Prefabs at Edit time
    • Asset management
      • Instantiating from CoherenceSyncConfig
      • Instantiate via
      • Load via
    • Scene management
    • Multiple Connections within a Game Instance
    • Baking (code generation)
      • Conditional compilation
    • Replication Server
      • Rooms and Worlds
      • Replication Server API
    • Simulators (Servers)
      • Scripting: Client vs Simulator
      • Run local Simulators
      • World Simulators
      • Room Simulators
      • Advanced Simulator Authority
      • Simulator slugs
      • Build and Deploy
      • Command-line arguments
    • Client Connections
    • Optimization
      • Areas of Interest
      • Level of Detail (LOD)
      • Profiling
      • Simulation Frequency
    • Project Settings
    • Advanced topics
      • Big worlds
        • World Origin Shifting
        • Load balancing
      • Competitive games
        • Simulation Frame
        • Determinism, Prediction and Rollback
      • Team workflows
        • Version Control integration
        • Continuous Integration
      • Schema explained
        • Specification
        • Field settings
        • Archetypes
      • Code stripping
      • Replication Server CLI
      • Single-player gameplay
    • Scripting API
  • Hosting
    • Choosing where to host
    • coherence Cloud
      • Online Dashboard
      • Manage Worlds
      • Configure Rooms
      • Player Accounts
      • Game Services
        • Lobbies
        • Cloud Storage
        • Key-Value Store (Legacy)
      • APIs
        • Worlds
        • Rooms
        • Lobbies
        • Cloud Storage
        • Key-Value Store (Legacy)
    • Peer-to-peer
      • Implementing Client hosting
        • Steam Relay
        • Epic Online Services (EOS) Relay
        • Azure PlayFab Relay
  • Support
    • Release notes
    • Glossary
    • Unreal Engine support
    • WebGL support
    • ECS / DOTS support
    • Known issues
    • Upgrade guide
      • Upgrade 1.6 -> 1.7
      • Upgrade 1.5 -> 1.6
      • Upgrade 1.4 -> 1.5
      • Upgrade 1.3 -> 1.4
      • Upgrade 1.2 -> 1.3
      • Upgrade 1.1 -> 1.2
      • Upgrade 1.0 -> 1.1
      • Upgrade 0.10 -> 1.0
      • Upgrade 0.9 -> 0.10
    • Credit cost & pricing
    • Report a bug
Powered by GitBook
On this page
  • Storage Object Identifier
  • Usage
  • Saving Objects
  • Loading Objects
  • Deleting Objects
  • Storage Operation
  • Async Methods
  • Coroutines
  • Callbacks
  • Error Handling
  • Serialization
  • Supported Types
  • Throttling
  • Other Considerations

Was this helpful?

Export as PDF
  1. Hosting
  2. coherence Cloud
  3. Game Services

Cloud Storage

Store data in the cloud

Was this helpful?

Cloud Storage is a general data storage service offered within the coherence Cloud.

Storage Object Identifier

Objects stored in cloud storage are identified using a tuple called storage object identifier or StorageObjectId.

The storage object identifier consists of a type and an id. Type is intended to describe the general category that the object belongs to - for example, "Player" or "Settings" - and id is intended to uniquely distinguish the object from all other objects with the same type.

For example, to store player-specific data in cloud storage, you can set id to be the :

StorageObjectId playerInventoryId = ("PlayerInventory", PlayerAccount.Main.Id);

The StorageObjectId type is serializable by Unity, and can also be edited using the Inspector as a serialized field.

public StorageObjectId objectId = ("Level", Guid.NewGuid());

Usage

You must be logged in coherence Cloud to use this service. Read more about authentication on the page.

provides three methods, allowing you to , and objects.

Saving Objects

The method can be used to save an object to cloud storage.

using Coherence.Toolkit;
using UnityEngine;

class SaveExample : MonoBehaviour
{
    public StorageObjectId objectId = ("Greeter", 1);

    async void Start()
    {
        // Get main player account once it has logged in.
        PlayerAccount playerAccount = await PlayerAccount.GetMainAsync();
        
        // Save the string "Hello, World!" in cloud storage:
        var cloudStorage => playerAccount.Services.CloudStorage;
        await cloudStorage.SaveObjectAsync(objectId, "Hello, World!");
    }
}

Loading Objects

// Load a string from cloud storage:
string text = await cloudStorage.LoadObjectAsync(objectId);
Debug.Log(text);

Deleting Objects

// Delete a string from cloud storage:
await cloudStorage.DeleteObjectAsync(objectId);

Storage Operation

Async Methods

async void AsyncMethod(StorageOperation operation)
{
    await operation;
    Debug.Log(operation);
}

Coroutines

IEnumerator Coroutine(StorageOperation operation)
{
    yield return operation;
    Debug.Log(operation);
}

Callbacks

void Method(StorageOperation<string> operation)
{
    operation.OnSuccess(result => Debug.Log($"Result: {result}"));
             .OnFail(error => Debug.LogWarning(error));
}

Error Handling

async void Start()
{
    var operation = await CloudStorage.LoadObjectAsync<string[]>(objectId, destroyCancellationToken);
    if(operation.HasFailed)
    {
        Debug.LogWarning(operation.Error);
        return;
    }
    
    if(operation.IsCanceled)
    {
        Debug.LogWarning("Operation was canceled");
        return;
    }
    
    foreach(string item in operation.Result)
    {
        Debug.Log($"Loaded item: \"{item}\".");
    }
}

Serialization

By default all the public properties and fields of objects are serialized.

Supported Types

Throttling

coherence Cloud has a rate limit of one API request of a particular type per second.

Having a rate limit of one API request of a type per second means is that if, for example, a save operation is made while another save operation is already in progress, then the second save operation will be queued, and will only get sent to the backend after one second has passed since the previous save operation.

However, the Cloud Storage service is able to automatically batch multiple storage operations into a single API request behind-the-scenes, which means that in practice an operation should almost never have to sit in queue for more than a second.

Other Considerations

Currently, data is held for one hour. In the future, this will be configurable.

Any client can read or write storage objects at any time. Data is available as long as the client knows the identifier to access it.

The method can be used to load an object from cloud storage.

The method can be used to delete an object from cloud storage.

All of CloudStorage's methods return a or a .

These are objects. Methods that contain the keyword can use to wait for the operation to complete:

Coroutines can also use to wait for the operation to complete:

It is also possible to execute a function when the operation completes successfully or fails, using and respectively.

If you need further info on how to do asynchronous programming within Unity, check out their .

StorageOperations never cause to be thrown, even if you use the await or yield keywords with them. Instead, it is expected that you will detect and handle errors manually.

You can determine if a completed StorageOperation has failed using the property. If an operation has failed, you can acquire more information about the failure via the object found in the property.

When an object is saved to cloud storage, its state is serialized to JSON using .

You can use Json.NET's to control how Json.NET serializes and deserializes your object.

In addition to supporting all the (primitive types, arrays, lists, dictionaries...), Cloud Storage also supports the following Unity types:

Saving and loading objects whose type derives from is not supported. You can however serialize a UnityEngine.Object into a string using the built-in , and then save that string in cloud storage instead.

identifier of a player account
Player Accounts
The CloudStorage API
save
load
delete
SaveObjectAsync
LoadObjectAsync
DeleteObjectAsync
StorageOperation
StorageOperation<TResult>
Task-like
async
await
yield return
OnSuccess
OnFail
documentation
exceptions
HasFailed
StorageError
Error
Json.NET
serialization attributes
types that Json.NET can handle by default
Vector2
Vector3
Quaternion
Color
Color32
UnityEngine.Object
JsonUtility