Steamworks 文獻庫
Steam 雲端服務
簡介
Steam 雲端會自動將遊戲中的檔案儲存至 Steam 伺服器,玩家無論從哪一台電腦登入 Steam,都能取用遊戲存檔。
整合層級
您需要在 Steamworks 網站上設定檔案路徑。 您也可以選擇在遊戲程式碼中使用某些 API 呼叫 Steamworks 來進行上傳、下載、列舉和刪除。

Steam 雲端服務概覽

Steam 雲端為您的遊戲提供一個簡單透明的遠端檔案儲存系統。 在自動雲端配置中指定的檔案或使用雲端 API 寫入(建立、修改、刪除等)磁碟的檔案,將在遊戲關閉後自動複製到 Steam 伺服器上。

如果使用者換了一台電腦,在遊戲啟動之前,檔案會自動下載到新電腦上。 然後,遊戲可透過雲端 API 讀取檔案,或像往常一樣直接從磁碟讀取檔案。 請避開影片設定等針對個別電腦的配置。

Steam 用戶端會確保在使用者可能使用的所有電腦上,檔案都能保持同步。

使用者可以在 Steam 雲端設定下透過取消勾選「為支援的應用程式啟用 Steam 雲端同步功能」來全面停用雲端同步。

使用者還可以在各別遊戲的屬性中選擇性地停用雲端同步。

Spacewar_Cloud_Properties.png

備註和最佳作法


有一點很重要,Steam 會在每個工作階段前後,為您的遊戲的使用者 Steam 雲端檔案進行同步。 任何相符檔案只要在工作階段期間有所變更,都會在變更發生後立即上傳到雲端儲存空間。 要是遊戲將非常龐大的檔案或許多小檔案寫入 Steam 雲端,可能會明顯影響使用者的網路頻寬,使得關閉 Steam 或重新啟動遊戲的速度變慢。

較小的檔案通常處理起來比較流暢。 如果某個使用者的儲存狀態可以分為常變動和不常變動這兩類,我們建議可以按照這些特性,將檔案拆成數個。 這樣可以省得在每個工作階段之後,又重新上傳未變更的狀態。

檔案大小限制


Steam 雲端的絕對檔案大小限制可能會隨著時間改變。 下面是現行的限制和門檻值:

大小限制
100MBMaximum size for a call to ISteamRemoteStorage::FileWrite or ISteamRemoteStorage::FileWriteStreamWriteChunk
256MB可能導致使用者位置的儲存點選擇不理想,拖累上傳 / 下載性能

Save File Paths

When deciding where to write your save files, be sure the path will be unique for the current Steam user. If needed, you can get the user's unique Steam ID via ISteamUser::GetSteamID. From that, you can access their accountID from GetAccountID(), allowing you to have a unique variable when constructing your save path.

Cross-Platform Saves


If your game is supported on multiple platforms - or even if you plan to support this in the future - you should consider this when setting up Steam Cloud for your game.

If you plan to read/write files directly via the ISteamRemoteStorage interface, then you can control platform sync via ISteamRemoteStorage::SetSyncPlatforms. The default for a new file is to sync to all platforms.

If you plan to use Steam Auto-Cloud, there are some key things to know. First, the default for new files is to sync to only the OS setting on the associated Auto Cloud Root path. This means that if you set up distinct roots for each OS, all files will be partitioned by platform, and hence there will be no cross-platform save functionality.

To enable cross-platform saves, you should instead define a single Root path (likely for Windows), and then create Root Overrides for the other supported platforms. Files matching a given Root path which also has platform Root Overrides will sync to all platforms in both the origianal Root and all Overrides. See the Steam Auto-Cloud documentation for more details.

初始設定

To set up Steam Cloud you must set the Byte quota per user and Number of files allowed per user options on the Steam Cloud Settings page in the Steamworks App Admin panel.

This quota is enforced on each Cloud-enabled game, on a per-user-per-game basis. It's recommended to set the values to reasonable amounts for your game title.

備註: Don't forget to click Save at the bottom of the page, and Publish your updated settings. Once published the cloud icon will be visible in the Steam client for anyone that owns your game.

If your game has already been released to the public then you can check the box labeled Enable cloud support for developers only. If developers-only mode is enabled then only the steam accounts which own a "Developer Comp" license for your title will see the cloud icon and will be able to use the Steam Cloud. This is useful to safely test Steam Cloud integration without breaking the public user experience. This has no effect on unreleased games since no one owns the game yet, they won't be able to see or access any cloud storage for the specific app ID.

You are able to share Cloud storage space between two app IDs by filling out the Shared cloud APP ID field. This is most commonly used to share saved games between a demo and a full game. A value of 0 disables this feature.

Steam 雲端 API 和 Steam 自動雲端

Steam provides two different methods of utilizing the Steam Cloud, read up on how the two methods differ, and determine which would be the best for your application.

First up is the Steam Cloud API.
The Cloud API provides a series of functions which allows you to directly integrate the Steam Cloud into your game. The Cloud API isolates individual Steam users files from each other and provides a greater level of control over the Steam Cloud.

The Steam Cloud API is exposed via the ISteamRemoteStorage API interface, and you can find example usage in the Steamworks API 範例應用程式(SpaceWar) project.

The second is Steam Auto-Cloud.
Steam Auto-Cloud was designed for games where you choose to not integrate the Steam Cloud API. It provides a quick and easy way to get started but lacks the flexibility that is available with the Steam Cloud API.

If you prefer a deeper integration with Steam Cloud (for example, allowing to choose which save files are stored in the cloud), then you should use the Cloud API. Otherwise you can use Steam Auto-Cloud.

Steam 自動雲端

Steam Auto-Cloud is an alternative to the Steam Cloud API that allows apps to use Steam Cloud without writing code or modifying the game in any way. It only requires that you specify the file groups which you want persisted to the Cloud. Steam will automatically sync the groups of files when the application launches and exits. Avoid machine specific configurations such as video quality.
Note: The file steam_autocloud.vdf will be created in each location specified by your Steamworks cloud paths. This file is used by Steam, and can be ignored by your game.

Setup

After completing the 初始設定 the Steam Auto-Cloud configuration section will unlock on the Steam Cloud Settings page.

Root Paths describe groups of files which will be persisted to the Steam Cloud. Each Root Path can be as specific as a single file or as wide as all files under a given subfolder. Use a new path for each group of files to sync.

A Root Path is composed of 5 parts:
  1. 這是一個預先確定的路徑列表,遊戲儲存通常位於此處。
    支援的作業系統相應路徑
    應用程式安裝目錄所有[Steam Install]\SteamApps\common\[Game Folder]\
    SteamCloudDocuments所有平台特定路徑,Linux 平台的例子:~/.SteamCloud/[username]/[Game Folder]/
    WinMyDocumentsWindows%USERPROFILE%\My Documents\
    WinAppDataLocalWindows%USERPROFILE%\AppData\Local\
    WinAppDataLocalLowWindows%USERPROFILE%\AppData\LocalLow\
    WinAppDataRoamingWindows%USERPROFILE%\AppData\Roaming\
    WinSavedGamesWindows%USERPROFILE%\Saved Games\
    MacHomemacOS~/
    MacAppSupportmacOS~/Library/Application Support/
    MacDocumentsmacOS~/Documents/
    LinuxHomeLinux~/
    LinuxXdgDataHomeLinux$XDG\_DATA\_HOME/
  2. 子目錄

    與根相關的雲端檔案的子目錄路徑。 如子目錄不存在,請使用「.」。

    自動雲端特殊路徑值
    自動雲端允許在子目錄路徑中使用獨特的 Steam 使用者識別碼。 如此您便可以為電腦中的每位 Steam 使用者分別儲存檔案。 您可也以在自己的遊戲中使用 ISteamUser::GetSteamID 獲取目前使用者的 SteamID 或 AccountID 用於儲存和讀取。
    • {64BitSteamID} - 在 Steam 路徑中使用此變數,插入使用者的 64 位元 Steam ID。 64 位元的 Steam ID 範例:76561198027391269
    • {Steam3AccountID} - 在 Steam 路徑中使用此變數,插入使用者的 3 位元 Steam ID。 Account ID 的範例:67125541
    範例:SavesDir/{64BitSteamID}
  3. 模式

    應相符的檔案遮罩模式。 您可使用 * 作為萬用字元。 如果您希望目錄中包括所有檔案,只需使用 *

    範例:*.sav
  4. 作業系統

    設定這些檔案的來源和將同步至的作業系統。 這個步驟只有在檔案僅適用於特定作業系統時才有必要,希望這種情況不會發生!
  5. 遞迴

    搜尋相符的檔案時包含子目錄。 在處理名稱不具判別性(如名稱不為 Steam 使用者名稱或 ID)的子目錄時,此設定很有幫助。 如果使用 Steam ID,我們強烈推薦在子目錄欄位中使用特殊路徑值。

Root Overrides

If your application is cross-platform and requires different directories for each OS. You can use the Root Overrides functionality to specify an override the Root Paths that you set above.

The root paths specified above can be overridden to correspond to a different path on another OS. If you use Root Overrides, you must specify [All OSes] in the Root OS drop down above.

A Root Override consists of 5 parts.
  1. 原始根目錄

    對應於您上面設置的根之一。
  2. 作業系統

    執行覆寫的目標作業系統。
  3. 新根

    原始根對應到指定作業系統中的新位置。
  4. 新增 / 替換路徑

    您可以選擇性地添加插入新根和原始子目錄之間的子目錄路徑。
  5. 替換路徑

    一旦啟用,將導致在新增或替換路徑中指定的路徑完全取代原始子目錄。

Example: Configuring Auto-Cloud for Unity Applications

The following is an example of setting up Auto-Cloud for use with Unity and the Application.persistentDataPath property where the value is different per OS. The Windows version is configured as the Root Path with the company in Unity set to DefaultCompany and the Project called AutocloudSample. On macOS and Linux/SteamOS, the alternate paths from Application.persistentDataPath are set in the Add/Replace Path field and Replace Path is enabled.

With these settings, Auto-Cloud files will be synchronized between the three folders as shown in the Preview samples.

Cloud_Unity_Auto-Cloud_Example.png

Pre-release Testing

If you are adding Steam Auto-Cloud to a game which is already released and you have enabled developer-only mode during the 初始設定 then you must complete some additional steps to test the functionality.
  1. Sign in to Steam with an account that owns the app that you are testing.
  2. 使用瀏覽器打開 steam://open/console 以開啟 Steam 主控台
  3. 在主控台中輸入 testappcloudpaths<AppId> 以及您正在測試的應用程式的特定 App ID, 例如:testappcloudpaths 480
  4. 在主控台中輸入 set_spew_level 4 4
  5. 從 Steam 啟動您的應用程式
  6. 檢查主控台活動,如果檔案已經存在於自動雲端路徑中,那麼您應該可以看到這些檔案被上傳。 否則,從您的應用程式中儲存一些檔案,然後關閉此應用程式來觸發同步
  7. 換另一台電腦重複以上步驟,測試從 Steam 自動雲端下載檔案
  8. 務必在所有支援的作業系統上進行測試
  9. Set testappcloudpaths 0 and set_spew_level 0 0 to end testing. 您可重新啟動 Steam 用戶端以刪除主控台分頁

Don't forget to disable developers-only mode and publish the changes when you're done testing.

Dynamic Cloud Sync


Steam Cloud now supports dynamic sync - where changes appearing in the Cloud can be downloaded to the local machine during an application session. The current example is a suspended game session on the Steam Deck. For apps marked as supporting dynamic Cloud sync, Steam will synchronize files up to the Steam Cloud at the suspend time. Then, the user may run the game on another device, which will receive the updates from the Steam Deck session at launch. At exit, those changes will be uploaded to the Steam Cloud. Finally, when the Steam Deck device is awakened, Steam will synchronize the changes down to that device, and post a notification to the application that local files have changed. The application can then iterate those changes and take appropriate action. For instance, the game may be able to simply load the updated progress from disk and allow the user to pick up right where they left off on the other device.

Check out our announcement post for even more information about why this feature exists, and how to use it.

Note that this feature supports applications whether they use the ISteamRemoteStorage API to manage files, or Auto-Cloud.

For more details, see the ISteamRemoteStorage documentation, specifically ISteamRemoteStorage::RemoteStorageLocalFileChange_t, ISteamRemoteStorage::GetLocalFileChangeCount, and ISteamRemoteStorage::GetLocalFileChange.

See also ISteamRemoteStorage::BeginFileWriteBatch and ISteamRemoteStorage::EndFileWriteBatch - these wrappers should be used to provide hints to Steam which will help it safely sync up to the Steam Cloud at the time when the user initiates a system suspend.

Pre-release Testing


You can locally enable Dynamic Cloud Sync for your app to test your builds - this is recommended for a game that has already shipped, as enabling Dynamic Cloud Sync for all users could lead to data loss when running builds that do not handle the new API methods and callbacks.

To test locally from a PC:

  1. Sign in to Steam with an account that owns the app that you are testing.
  2. Open the Steam Console by navigating to steam://open/console in your browser. (You can also run Steam with the command-line steam -console and then navigate to the Console section directly).
  3. Enter @cloud_testdynamicsyncapp <AppId> into the console with the given App ID that you are testing. Ex: @cloud_testdynamicsyncapp 480
  4. Launch your app from Steam.
  5. Progress through the game to a desired amount
  6. In the Steam Console, enter prepare_for_suspend. Steam will suspend your game process and upload any changed files to the Steam Cloud.
  7. Optional: play the game on another device, creating further progress, and then exit and let that Steam client upload progress to the Steam Cloud.
  8. Back on the original device, in the Steam Console, enter resume_suspended_games. This will sync down any necessary files from the Steam Cloud, post the relevant API calls to your game, then un-suspend your game process.

To test locally from a Steam Deck:

  1. Connect your Steam Deck with a Devkit
  2. To use the CEF Console, see here
  3. In the JS console, enter SteamClient.Console.ExecCommand(“@cloud_testdynamicsyncapp <AppId>”) to enable testing. You can then enter SteamClient.Console.ExecCommand(“@cloud_testdynamicsyncapp 0”) to disable it

Debugging

First, always ensure that you have published your changes on the Steam partner website and have waited up to 10 minutes or restarted your Steam client to receive the published changes.

If you run into issues with Steam Cloud you should check the log file located at %Steam Install%\logs\cloud_log.txt.

See Debugging the Steamworks API for additional information.