Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Game Saves is designed to work both online and offline, allowing players to continue playing even when network connectivity is unavailable. The system operates in two distinct modes based on network availability and user choices.
Connection Modes
Connected to Cloud Mode
When network is available and PFGameSaveFilesAddUserWithUiAsync() completes successfully, the system operates in connected to cloud mode. In this mode:
- All APIs function normally with full cloud synchronization
- Save data uploads work as expected
- Storage quota information is available
- Active device monitoring works properly
Offline Mode (Not Connected to Cloud)
When network is unavailable or the user chooses to play offline, the system enters offline mode with limited functionality. You can check the current connection status using PFGameSaveFilesIsConnectedToCloud() to determine which mode the system is operating in.
Handling Network Failures During Initial Sync
When PFGameSaveFilesAddUserWithUiAsync() is called without network connectivity, it triggers a PFGameSaveFilesUiSyncFailedCallback. The XAsyncBlock callback doesn't fire while the system waits for the user's response—the async operation is paused until the user selects a terminal action.
// Handle sync failure callback
void MyPFGameSaveFilesUiSyncFailedCallback(PFLocalUserHandle localUserHandle, PFGameSaveFilesSyncState syncState, HRESULT error, void* context)
{
// Tell the user something like this:
std::cout << "We couldn't sync your data with the cloud just now" << std::endl;
std::cout << "Try syncing again or use this game offline" << std::endl;
std::cout << "[Try Again]" << std::endl;
std::cout << "[Use Offline]" << std::endl;
// if user chooses [Try Again], call PFGameSaveFilesSetUiSyncFailedResponse(localUserHandle, PFGameSaveFilesUiSyncFailedUserAction::Retry);
// if user chooses [Use Offline], call PFGameSaveFilesSetUiSyncFailedResponse(localUserHandle, PFGameSaveFilesUiSyncFailedUserAction::UseOffline);
// These API calls can happen inside or outside of this callback
}
User Response Options:
- Try Again (
Retry): Retries the network call. If the retry also fails, this callback fires again and the user must respond again. TheXAsyncBlockcallback remains deferred through each retry loop. - Use Offline (
UseOffline): TheXAsyncBlockcallback fires withS_OK, but the system enters offline mode (detectable withPFGameSaveFilesIsConnectedToCloud()). - Cancel: The
XAsyncBlockcallback fires withE_PF_GAMESAVE_USER_CANCELLED.
API Behavior in Offline Mode
When in offline mode, APIs behave differently:
APIs That Work Normally
PFGameSaveFilesGetFolder()- Returns local save folder path
APIs With Limited Functionality
PFGameSaveFilesUploadWithUiAsync()- ReturnsS_OKimmediately, but async completion returnsE_PF_GAMESAVE_DISCONNECTED_FROM_CLOUDPFGameSaveFilesGetRemainingQuota()- ReturnsE_PF_GAMESAVE_DISCONNECTED_FROM_CLOUDPFGameSaveFilesSetActiveDeviceChangedCallback()- Can be set but will never trigger
Returning to Online Mode
- Call
PFGameSaveFilesAddUserWithUiAsync()again to attempt reconnection - No need to fully re-initialize the Game Saves system
- Will show failure UI again if network is still unavailable
- Use
PFGameSaveFilesIsConnectedToCloud()to verify connection status after retry attempts
Additional Connection Status Scenarios
The PFGameSaveFilesIsConnectedToCloud() API is particularly useful because disconnection can happen in multiple ways:
- Network unavailable during sync: User explicitly chooses to play offline
- Active device changed: Another device takes over as the active device, automatically putting this device in offline mode
Use this API before attempting cloud operations to provide appropriate user feedback.
Best Practices for Offline Support
- Always implement sync failure callbacks to handle network issues gracefully
- Check connection status regularly using
PFGameSaveFilesIsConnectedToCloud()before attempting cloud operations - Inform players when operating in offline mode so they understand saves won't sync
- Provide retry options when network connectivity is restored
- Local saves always work - players can continue playing regardless of network status
- Monitor for disconnection - remember that devices can be disconnected when another device becomes active
Upload Behavior in Connected Mode
Even in connected mode, uploads can fail due to network issues or rate limits. When this happens, the XAsyncBlock callback doesn't fire immediately—the async operation pauses while the system waits for the user's response through the UI callback state machine:
- The
PFGameSaveFilesUiSyncFailedCallbackfires with the error details. - The
XAsyncBlockcallback doesn't fire yet—the operation is paused while the system waits for a response. - If the user selects
Retry, the upload retries. If it fails again, the callback fires again and the user must respond again. - If the user selects
Cancel, theXAsyncBlockcallback fires withE_PF_GAMESAVE_USER_CANCELLED. - If a retry succeeds, the
XAsyncBlockcallback fires withS_OK.
The game can call PFGameSaveFilesUploadWithUiAsync() again later when network is restored.