Save Scriptable Object with List of Gameobjects

Hello, I’ve an problem with my save system.

When you run the game in the unity editor and do some changes in an scriptable object it saves it by it self, but if you build the game and you change something to an scriptable object is won’t save.

But I’ve an Scriptable Object (class inventorycar) and I want it that if you add or remove an item that is save the changes. But I got an problem. Possible somebody can help me with this problem.
Thankyou in advance !

Code (CSharp):

  • Class 1:
[System.Serializable]
[CreateAssetMenu(fileName = "Data", menuName = "Inventory/L istCar", order = 1)]
public class InventoryCar : ScriptableObject {
    public List<ItemCar> InventoryItem = new List<ItemCar>();
    public bool b_mobile = false;
    public float mobileMaxSpeedOffset = 0;
    public float mobileWheelStearingOffsetReactivity = 0;
    public bool b_Countdown = true;
    public bool b_LapCounter = true;

    public int SavedListCount;


    public void SaveList()
    {
        for (int i = 0; i < InventoryItem.Count; i++)
        {
            PlayerPrefs.SetString("TotalCars" + i, InventoryItem[i].Cars.());
        }
        PlayerPrefs.SetInt("Count", InventoryItem.Count);
    }

    public void LoadList()
    {
        InventoryItem.Clear();
        SavedListCount = PlayerPrefs.GetInt("Count");

        for (int i = 0; i < SavedListCount; i++)
        {
            ItemCar cars = PlayerPrefs.GetString("TotalCars" + i.ToString());
            InventoryItem.Add(cars);
        }
    }

Script 2:

Code (CSharp):


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    [System.Serializable]
    public class ItemCar
    {
        [SerializeField]
        public List<GameObject> Cars = new List<GameObject>();

      
    }

ScriptableObjects do not save changes in builds. That’s the nature of them. You will need to find another way to save your changes. You could then load in the scriptableObject data and then use the extra saved changes to overwrite the values.

1 Like

@Brathnann Thankyou for your response. Could you possible help me with this problem?

What problem? This was back in Oct and I mentioned how you had to address the scriptableObjects. If your scriptableObject is, for example, a car, then you load up that cars scriptableObject like normal. But, if that player has bought a custom steering wheel, then you have to also load the players save data and when they go to view their car, you swap out the steering wheel for the custom one.