SaveObjectAsync
method in Coherence.Cloud.CloudStorage
Methods
public StorageOperation SaveObjectAsync<TObject>(StorageObjectId objectId, TObject @object, CancellationToken cancellationToken = default)
Saves an object to cloud storage.
Parameters
| Type | Name | Description |
|---|---|---|
| StorageObjectId | objectId | Identifier of the object to save. |
| TObject | object | The object to save. |
| CancellationToken | cancellationToken | Used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| StorageOperation | The status of the asynchronous save operation. |
Type Parameters
| Name | Description |
|---|---|
| TObject | Type of the object to save. |
Remarks
If an object with the id already exists in cloud storage, it will be overwritten.
Examples
using Coherence.Cloud;
using UnityEngine;
class CloudStorageSave : MonoBehaviour
{
async void Start()
{
PlayerAccount playerAccount = await PlayerAccount.GetMainAsync();
var cloudStorage = playerAccount.Services.GameServices.CloudStorage;
var objectId = ("Greeter", 1);
await cloudStorage.SaveObjectAsync(objectId, "Hello, World!")
.OnFail(Debug.LogWarning)
.OnSuccess(() => Debug.Log("Saved"));
}
}
Exceptions
| Type | Condition |
|---|---|
| StorageException | If the user is not logged in via AuthClient, the operation will fail with NotLoggedIn. |