Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Cloud Save and Serializable objects throwing errors

Discussion in 'Cloud Save' started by LiterallyJeff, Mar 12, 2023.

  1. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    Hello,

    I'm currently trying to save a list of player-selected cosmetic items to Cloud Save service.

    The list is of type "List<AssetReference>". I have had no problems serializing and saving these objects locally to a file using JsonUtility.

    I am now experimenting with moving certain save data into the cloud.

    However, when I try to send the same data to Cloud Save, I'm getting this error:
    My code:
    Code (CSharp):
    1. List<AssetReference> items; // passed in parameter
    2. Dictionary<string, object> dataDictionary = new()
    3. {
    4.     { "EquippedItems", items }
    5. };
    6.  
    7. await CloudSaveService.Instance.Data.ForceSaveAsync(dataDictionary);
    I'm assuming that the Dictionary value "object" is valid for any serializable type, correct?

    What is happening here? I can serialize these objects with no issue locally, so why would there be an issue with Cloud Save? Are there some serialization limitations specific to Cloud Save I'm not aware of?
     
    Last edited: Mar 12, 2023
  2. rambod

    rambod

    Unity Technologies

    Joined:
    Mar 2, 2018
    Posts:
    58
    Thanks for flagging this @LiterallyJeff, we'll take a look on our end. In the meantime, one workaround is using JsonUtility to serialise the dictionary into JSON then upload that into Cloud Save.
     
    LiterallyJeff likes this.
  3. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    Looks like saving out just the AssetGUIDs string from the AssetReferences, and then loading them at runtime using "new AssetReference(guid)" and loading assets via Addressables.LoadAssetAsync / InstantiateAsync using that AssetReference as the key can work just fine, and the string array is way friendlier for json and CloudSave.
     
    Last edited: Mar 15, 2023
  4. icosajim

    icosajim

    Joined:
    Mar 28, 2015
    Posts:
    2
    Anyone else seeing this error and not knowing what's up, for us once we dug in, we found a "can only call this from the main thread" inner exception. We were trying to call it outside of the proper scope. So moved it in to a coroutine and all was well.