docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Interface ISaveWritable

    Save opened for writing.

    Inherited Members
    IAsyncDisposable.DisposeAsync()
    IDisposable.Dispose()
    Namespace: Unity.PlatformToolkit
    Assembly: Unity.PlatformToolkit.dll
    Syntax
    public interface ISaveWritable : IAsyncDisposable, IDisposable
    Remarks

    ISaveWritable allows modifying multiple files within a save and committing them in a single operation. Changes to the save are first queued up by calling WriteFile(string, byte[]), DeleteFile(string), SetImage, Description, then changes are commited by calling Commit(). If Commit() completes without exceptions, all queued up changes were written to disk successfully. If Commit() throws an exception, no changes are made to existing data on disk.

    A save must be disposed before it can be opened again. If ISaveWritable is opened, it must be disposed before calling OpenSaveReadable(string) or OpenSaveWritable(string) with the same save name.

    Calling dispose discards any changes made to the save.

    Methods

    Commit()

    Commit changes made to the save.

    Declaration
    Task Commit()
    Returns
    Type Description
    Task

    Task representing the commit operation.

    Remarks

    If a file already exists in the save and was not modified, Commit() will leave it as is.

    Commit disposes the ISaveWritable. This is true regardless if the commit succeeded or failed.

    When a commit fails with an exception no changes will be made to the save. Any changes waiting to be committed are discarded.

    Commit will fail if the save does not contain any files. This includes new empty saves, or existing save when attempting to delete all the files.

    If a commit is not completed succesfully when creating, the save may still be created but remain empty.

    Exceptions
    Type Condition
    IOException

    There was an error commiting the data.

    NotEnoughSpaceException

    There is not enough space to write the data. This can mean that the system is out of memory, but other limits can also be imposed by platforms. For example limits on how much storage is allocated for each account or how large a single commit can be.

    InvalidAccountException

    IAccount is signed out.

    InvalidSystemException

    ISavingSystem is invalid.

    InvalidOperationException

    Save is empty

    See Also
    ISavingSystem
    OpenSaveWritable(string)

    DeleteFile(string)

    Delete a file.

    Declaration
    Task DeleteFile(string name)
    Parameters
    Type Name Description
    string name

    Name of the file.

    Returns
    Type Description
    Task

    Task representing the file deletion operation.

    Remarks

    Attempts to delete a non-existent file are ignored.

    If a file is written with WriteFile(string, byte[]) and then deleted with DeleteFile(string), the WriteFile(string, byte[]) is canceled out and the file will be deleted or not created at all if it did not exist on disk.

    Exceptions
    Type Condition
    ArgumentException

    The name is null or empty, contains invalid characters or is too long.

    IOException

    There was an error deleting the data.

    InvalidAccountException

    IAccount is signed out.

    InvalidSystemException

    ISavingSystem is invalid.

    See Also
    ISavingSystem
    OpenSaveWritable(string)

    WriteFile(string, byte[])

    Write data into a file.

    Declaration
    Task WriteFile(string name, byte[] data)
    Parameters
    Type Name Description
    string name

    Name of the file.

    byte[] data

    Data to write.

    Returns
    Type Description
    Task

    Task representing the file writing operation.

    Remarks

    If a file with a given name does not exist WriteFile(string, byte[]) will create the file.

    If a file with a given name already exists WriteFile(string, byte[]) will overwrite the entire file.

    If a file is deleted with DeleteFile(string) and then written with WriteFile(string, byte[]), the DeleteFile(string) is canceled out.

    Exceptions
    Type Condition
    ArgumentException

    The name is null or empty, contains invalid characters or is too long.

    CorruptedSaveException

    The save has become corrupted, an empty save from a failed commit is considered corrupted.

    NotEnoughSpaceException

    There is not enough space to write the data. This can mean that the system is out of memory, but other limits can also be imposed by platforms. For example limits on how much storage is allocated for each account or how large a single commit can be.

    IOException

    There was an error writing the data.

    InvalidAccountException

    IAccount is signed out.

    InvalidSystemException

    ISavingSystem is invalid.

    See Also
    ISavingSystem
    OpenSaveWritable(string)

    See Also

    ISavingSystem
    OpenSaveWritable(string)
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)