I am trying to use Scriptable objects as a datatable of all of my skills as estated in this video
I have a Scriptable Object that contains an array of skills
public class SkillData : ScriptableObject
{
public Skill[ ] skills;
public void OnEnable()
{
if ( skills== null) skills = Resources.Load< SkillData>(“Data/ SkillData”). skills;
}
}
I have created an object of type SkillData and filled it manually with the data of the skills ( Title,descripcion,image…etc) and It works, however If ‘accidentaly’ set the element array size of the object ‘SkillData’ to 0 or use this statament
public class SkillData : ScriptableObject
{
public Skill[ ] skills;
public void OnEnable()
{
// Since my SkillData already created object is a SkillData type, when unity enable it call this fuction and erase my data
skills = new Skill[1];
}
}
My Skill Class:
[System.Serializable]
public class Skill
{
public int idSkill;
public string title;
public Sprite imagen;
public string descripcion;
public bool desbloqueado;
public int precio;
public GameObject skillScript;
}
All of my work will be deleted like if a do DROP Database ( on a real database),
It is very easy to erase all of the data by accident , so the question is
I am missing something? It is any way to ensure that the data will persist even if I erase all of the data?
Is there any way to ‘force’ unity ask you if you are sure to delete data or something similar? Is there a better way to store data in order to evade the erase of it?
Thanks in advance
If Skills are scripts (behaviours or ScriptableObjects) you won’t erase them directly, you’ll only erase that array.
Just try making a mock ScriptableObject with a Skill [ ] skills;
put your mock scripts into the array and then set it to 0. 
Thanks for answer, I updated the question with the Skill class, it is a class , that hold the info of the skill, what I want to achieve is not erase the array because in the array is where I fill the information about every skill, so If I erase the array, I erase all the data of my skills
Well, yes and no about “all of your information in the array”. The array will have references to your Skill class objects.
Those are what will hold the values, no? So erasing the array would only erasing the references to them, not the actual files (/data) . Unless I’m missing something.
I am assigning the information of the skills in the inspector array of the object Skill data ,
I created an SkillData object in my ScriptableObject folder
So to add an skill I am increasing the array by 1 , and adding the info on that array
Ah okay. So maybe a “safer” method , to put your mind at ease is to just make the Skill class a ScriptableObject also.
That way you can create them via the inspector and as you make them you can drag them to the list of the SkillData array.
If you don’t already have one, look for some code that creates an instance of a ScriptableObject asset. You can add them into the UI/menus. Then each new skill , click that menu item and you get a new asset you can edit.
Thanks, I did what you say and it works!