Search Unity

Question How to save data?

Discussion in 'Cloud Save' started by Durium, Feb 18, 2023.

  1. Durium

    Durium

    Joined:
    Feb 1, 2020
    Posts:
    37
    Hello! How do i save data? I dont really understand the limited documentation
    Following the "how to" in the docs gives me this issue with the CloudSaveService

    Code (CSharp):
    1. The type or namespace name 'CloudSave' does not exist in the namespace 'Unity.Services' (are you missing an assembly reference?)
     
  2. devingunity

    devingunity

    Unity Technologies

    Joined:
    May 26, 2021
    Posts:
    33
    Hi Durium, have you installed the Cloud Save package via the Package Manager, as outlined here? Errors like this usually occur when the package has not been imported.
     
  3. Mid_D_Man

    Mid_D_Man

    Joined:
    Jan 26, 2022
    Posts:
    22
    Hey can yp
    Hey can you please help me out, how do I load a boolean value from cloud save and set a local variable to it's value
     
  4. francoisjjunity

    francoisjjunity

    Unity Technologies

    Joined:
    Nov 23, 2020
    Posts:
    40
    Hi Mid_plays,

    Have a look at the documentation for some example usage https://docs.unity.com/cloud-save/en/manual/cloud-save-usage#Save_an_item.

    If you look at the "fetch item" section, you will notice that there is a variable called savedData. Access the previously saved boolean value by using the "key" to get the value like so
    Code (CSharp):
    1. savedData["key"]
     
  5. Mid_D_Man

    Mid_D_Man

    Joined:
    Jan 26, 2022
    Posts:
    22
    What I mean is like how do I use an of statement when I get the value like let's say I have a bool and when it's true I want the player to be able to jump twice as high as he normally does like if(SavedData["Key"].value == true ){ increase jumpCapacity();} something like that
     
  6. francoisjjunity

    francoisjjunity

    Unity Technologies

    Joined:
    Nov 23, 2020
    Posts:
    40
    Hi Mid_plays,

    Did you get it working? Using `SavedData["Key"].value == true` looks like it should work just fine if the value stored in the SavedData object is a boolean. This would not work if the value is actually a string value like "true".