Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Suduckgames · Apr 04, 2017 at 09:41 AM · databasescriptableobjectdatadata storage

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

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SohailBukhari · Apr 04, 2017 at 10:06 AM 0
Share

@username

$$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];
avatar image RobAnthem · Apr 04, 2017 at 10:23 AM 0
Share

$$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.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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");
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

70 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges