Usage

Cloud Services allows cross-device game data synchronization on iOS and Android.

Essential Kit wraps native iOS (iCloud Key-Value Store) and Android (Google Play Saved Games) APIs into a single Unity interface. Cloud Services automatically initializes with your Essential Kit settings and is ready to use.

Table of Contents

Understanding Cloud Services

Cloud Services keeps game data in two places:

  • Cloud copy – Lives in iCloud (iOS) or Google Play Saved Games (Android) and is shared across devices.

  • Device copy – Stored locally as a JSON cache; all CloudServices getters and setters read and write this copy instantly.

Synchronization keeps both copies in step. When you call Synchronize() the plugin uploads device changes, downloads cloud updates, and raises change events if the platform copy was newer.

Key characteristics:

  • All Get*/Set* calls update the device copy immediately

  • Synchronize() is the only way to push or pull the cloud copy

  • If the cloud copy is newer, it overwrites the device copy and fires OnSavedDataChange

Import Namespaces

Event Registration

Register for events in OnEnable and unregister in OnDisable:

Event
Trigger

OnUserChange

Cloud account changes (user logs in/out, switches accounts)

OnSavedDataChange

Cloud data differs from local data during sync (provides changed keys)

OnSynchronizeComplete

Synchronization request finishes (success or failure)

Local-Only Storage (No Cloud Sync)

Use Cloud Services as enhanced PlayerPrefs without any cloud synchronization:

Perfect for offline games or games that don't need cross-device sync. Data persists locally across sessions but won't sync to other devices.

Cloud Synchronization

Why Synchronization is Needed

Synchronization downloads the latest cloud data and uploads local changes. This ensures:

  • Fresh installs get saved progress from cloud

  • Players switching devices see their latest data

  • Concurrent device usage detects and resolves conflicts

First Sync (Authentication)

Call Synchronize() when your app starts to authenticate and download cloud data:

Checkpoint-Based Sync

Sync only at appropriate game checkpoints for performance:

Storing and Retrieving Data

Cloud Services supports primitive types and binary data as key-value pairs.

Supported Data Types

Storing Complex Data

Use a single serialized class for all save data to simplify versioning:

Key Management

Handling Data Conflicts

When the same data is modified on multiple devices, Cloud Services detects conflicts and fires OnSavedDataChange.

Understanding Conflict Resolution

Behind the scenes the plugin keeps a snapshot of the previous device values to help you compare changes:

  1. Player makes changes on Device A and syncs

  2. Player switches to Device B (has old data)

  3. Device B calls Synchronize() - cloud copy has newer data

  4. Local copy is overwritten with cloud copy

  5. OnSavedDataChange fires with changed keys and reason

  6. Your code compares the latest cloud values vs. the previous snapshot using CloudServicesUtility

  7. Choose winning value and set it back

  8. Next sync uploads the resolved data

Use CloudServicesUtility.TryGetCloudAndLocalCacheValues inside the event to fetch both values without manually caching them.

Example: Conflict Resolution

Change Reasons

Reason
Description

ServerChange

Cloud data differs from local data during sync

InitialSyncChange

First sync after fresh install (cloud data downloaded)

QuotaViolationChange

Exceeded storage limits - data reset to cloud copy

AccountChange

User switched cloud accounts - all keys invalidated

Conflict Resolution Pattern

Core APIs Reference

API
Purpose
Returns

CloudServices.SetBool(key, value)

Store boolean value locally

Void - syncs to cloud on next Synchronize()

CloudServices.GetBool(key)

Retrieve boolean value

bool (false if not found)

CloudServices.SetInt(key, value)

Store integer value locally

Void

CloudServices.GetInt(key)

Retrieve integer value

int (0 if not found)

CloudServices.SetLong(key, value)

Store long value locally

Void

CloudServices.GetLong(key)

Retrieve long value

long (0 if not found)

CloudServices.SetFloat(key, value)

Store float value locally

Void

CloudServices.GetFloat(key)

Retrieve float value

float (0.0 if not found)

CloudServices.SetDouble(key, value)

Store double value locally

Void

CloudServices.GetDouble(key)

Retrieve double value

double (0.0 if not found)

CloudServices.SetString(key, value)

Store string value locally

Void

CloudServices.GetString(key)

Retrieve string value

string (null if not found)

CloudServices.SetByteArray(key, value)

Store binary data locally

Void

CloudServices.GetByteArray(key)

Retrieve binary data

byte[] (null if not found)

CloudServices.HasKey(key)

Check if key exists

bool

CloudServices.RemoveKey(key)

Delete key-value pair

Void

CloudServices.GetSnapshot()

Get all data as dictionary

IDictionary

CloudServices.Synchronize(callback)

Sync local and cloud data

CloudServicesSynchronizeResult via callback

CloudServices.ActiveUser

Get current cloud user info

CloudUser (account status and user ID)

CloudServicesUtility.TryGetCloudAndLocalCacheValues<T>(key, out cloud, out local)

Compare cloud vs cache for conflicts

bool (true if both values exist)

Error Handling

Error Code
Trigger
Recommended Action

Sync failure (result.Success = false)

Network error, user denied authentication

Retry later or continue with local-only data

QuotaViolationChange reason

Exceeded storage limits

Compress data or remove unnecessary keys

AccountChange reason

User switched cloud accounts

Clear local data and reload from new account

Null/empty key

Invalid key parameter

Validate keys before calling Get/Set

Advanced: Runtime Settings Override

Understanding Advanced Initialization

Default Behavior: Essential Kit automatically initializes Cloud Services with settings from the ScriptableObject asset.

Advanced Usage: Override settings programmatically for:

  • Server-driven feature configuration

  • A/B testing different sync strategies

  • Dynamic platform-specific settings

  • Runtime feature flags

Implementation

  • Demo scene: Assets/Plugins/VoxelBusters/EssentialKit/Examples/Scenes/CloudServicesDemo.unity

  • Pair with Game Services for player authentication and leaderboards

  • See FAQ for common conflict resolution issues

  • Check Testing for cross-device validation procedures

Last updated

Was this helpful?