Search Unity

Question i made CloudSave script and i have error that CloudSave does not exist in the context how do i fix?

Discussion in 'Getting Started' started by unity_D3C1CCD9636DF07E35EC, Feb 5, 2024.

  1. unity_D3C1CCD9636DF07E35EC

    unity_D3C1CCD9636DF07E35EC

    Joined:
    Aug 4, 2023
    Posts:
    24
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Unity.Services.Core;
    5. using Unity.Services.CloudSave;
    6.  
    7. public class CloudManager : MonoBehaviour
    8. {
    9.     async void Start()
    10.     {
    11.         await UnityServices.InitializeAsync();
    12.  
    13.         await CloudSave.LoadAsync();
    14.  
    15.         await CloudSave.SaveAsync();
    16.     }
    17.  
    18.     void OnApplicationPause(bool pauseStatus)
    19.     {
    20.         if (pauseStatus)
    21.         {
    22.             CloudSave.SaveAsync().Wait();
    23.         }
    24.     }
    25.  
    26.     void OnApplicationQuit()
    27.     {
    28.         CloudSave.SaveAsync().Wait();
    29.     }
    30. }
    31.  
     
  2. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    490
    1. Open the Unity Editor.
    2. Go to the Package Manager (Window > Package Manager).
    3. In the Package Manager, make sure that the Unity Cloud Save package is installed. If not, search for it and install it.
     
  3. unity_D3C1CCD9636DF07E35EC

    unity_D3C1CCD9636DF07E35EC

    Joined:
    Aug 4, 2023
    Posts:
    24
    i did it
     

    Attached Files:

  4. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    490
    Example from manual. Try to remodel script you don't have all using (CloudSave.Models), you don't wait for authentication service, and you don't call service instance. Oh... and make sure you don't use own class CloudSave (name conflict).
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using Unity.Services.Authentication;
    3. using Unity.Services.CloudSave;
    4. using Unity.Services.CloudSave.Models;
    5. using Unity.Services.Core;
    6. using UnityEngine;
    7.  
    8. public class CloudSaveSample : MonoBehaviour
    9. {
    10.     private async void Awake()
    11.     {
    12.         await UnityServices.InitializeAsync();
    13.         await AuthenticationService.Instance.SignInAnonymouslyAsync();
    14.         SaveData();
    15.     }
    16.  
    17.     public async void SaveData()
    18.     {
    19.         var playerData = new Dictionary<string, object>{
    20.           {"firstKeyName", "a text value"},
    21.           {"secondKeyName", 123}
    22.         };
    23.         var result = await CloudSaveService.Instance.Data.Player.SaveAsync(playerData);
    24.         Debug.Log($"Saved data {string.Join(',', playerData)}");
    25.     }
    26. }
     
  5. unity_D3C1CCD9636DF07E35EC

    unity_D3C1CCD9636DF07E35EC

    Joined:
    Aug 4, 2023
    Posts:
    24
    i dont want authecation just cloud save
     
  6. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    490
    The Cloud Save package relies on the Authentication package.

    Manual
    Also add to your code so it can compile at least:
    Code (CSharp):
    1. using Unity.Services.CloudSave.Models;
    Look how the code is used in example, they call singleton Instance and you call non static methods.
    Code (CSharp):
    1. var result = await CloudSaveService.Instance.Data.Player.SaveAsync(playerData); // Them
    Code (CSharp):
    1. CloudSave.SaveAsync().Wait(); // You
    If you use CloudSave as your own class name then also will be errors. Because compiler don't know if you call Unity CloudSave or your CloudSave.

    There are errors on every level, so just copy and paste from manual that should work out of the box.
     
    Last edited: Feb 6, 2024
  7. unity_D3C1CCD9636DF07E35EC

    unity_D3C1CCD9636DF07E35EC

    Joined:
    Aug 4, 2023
    Posts:
    24
    no need now i found cloud save in asset store but thanks