Here is the code of my scriptable object:
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace ModelManager
{
[CreateAssetMenu(fileName = "New Texture Set", menuName = "Model Manager/New Texture Set")]
public class TextureSetSO : ScriptableObject
{
[SerializeField]
public RaceModelSO race;
public List<Textures> textures;
private RaceModelSO _race;
private void OnEnable()
{
_race = race;
}
private void OnValidate()
{
if (race != _race)
{
_race = race;
textures.Clear();
if (race)
{
if (race.GetRaceBodySlots().Length != 0)
{
for (int i = 0; i < race.GetRaceBodySlots().Length; i++)
{
Textures textures = new Textures();
textures.raceSlot = race.GetRaceBodySlots()[i];
this.textures.Add(textures);
}
}
}
}
EditorUtility.SetDirty(this);
AssetDatabase.SaveAssets();
}
private void OnDestroy()
{
AssetDatabase.SaveAssets();
}
private void OnDisable()
{
AssetDatabase.SaveAssets();
}
}
[Serializable]
public class Textures
{
public RaceSlotSO raceSlot;
public Texture normalMap;
public Texture albedoMap;
public Texture metalicMap;
public Texture ambientOcullsionMap;
public Texture emissionMap;
}
}
Whenever I use the editor to set anything inside the List<Textures> textures and then if I close Unity everything is getting lost.
Why is that? How can I keep the changes when close and open back Unity? Any way to store that info to the disk ?
OnEnable,OnDestroy,OnDisable,OnValidate...stuff I see in your script. Just inheriting from scriptable object, generation the instance from the menu option ([CreateAssetMenu...) and the dragging my fields to the[Serializable]classes exposed fields is enough. I suggest you might be overwritting your references in some of that logic in case its needed