- Home /
Scriptable Objects as a datatable
I am trying to use Scriptable objects as a datatable of all of my skills as estated in this video Overthrowing the MonoBehaviour Tyranny in a Glorious Scriptable Object Revolution
I have a Scriptable Object that contains an array of skills
[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;
}
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];
}
}
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
$$anonymous$$ake the array size const and initialize your array at deceleration. Whenever you will try to modify the value of const then run-time exception will throw.
public const int arraySize = 10;
public GameObject[] Objects = new GameObject[arraySize];
$$anonymous$$ake a custom inspector, or better yet, a creation suite of editor window tools that let you create and edit your entire data structure is an easy to view system.
Answer by Suduckgames · Apr 04, 2017 at 11:07 AM
I just change the way I organize my data, my skill class now derived from ScriptableObject and I have one per skill and they all are on a Resources>Data>Skill folder, then I load them all with
skills = Resources.LoadAll<Skill>("Data/Skills");
Your answer
Follow this Question
Related Questions
Data Management Issue - How to manage retrieved data from mysql? 0 Answers
How to upgrade from free to paid version and maintain established player prefrence data? 0 Answers
Storing Constant data in a mobile game 0 Answers
Why PlayerPrefs not working although I use "HasKey" and Save() on android? 0 Answers
Storing data on a server to be used for player currency in a multiplayer game 1 Answer