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 Ricardo42 · Feb 26, 2019 at 02:18 PM · listserializationscriptableobjectreloadserialize

List of ScriptableObjects lost on project reload

I'm trying to create a list of scriptableobjects, Grid, but for some reason I can't figure out, the instances of the Grid get reset when I restart the project. The actual list will have the same amount of objects in it, but they are all null.

How do I make sure the Grid objects are saved.

The instances don't get deleted when I switch between editor and play mode. It's just on project reload.

alt text alt text

gridislands.png (5.3 kB)
grid.png (2.1 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ymrasu · Feb 26, 2019 at 03:02 PM

To me, the idea behind ScriptableObjects is so you can have data as assests and work with them within the editor. With that said, if you have several ScriptableObject assests that you created that you want in a list, I would make a public array of them, drag and drop them onto the array in the editor, then convert the array into a list on start if wanted.

 public Grid[] gridArray;
 List<Grid> gridIslands;
 
 void Start() {
     gridIslands = new List<Grid>(gridArray);
 }

alt text


capture.png (3.8 kB)
Comment
Add comment · Show 2 · 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
avatar image Ricardo42 · Feb 26, 2019 at 03:16 PM 0
Share

I agree with your idea about using ScriptableObjects as data, that's what I'm trying to do here too. However, the grid scriptableobject isn't actually an asset. The data class which holds the gridIslands list is a scriptable object asset.

avatar image Ymrasu Ricardo42 · Feb 26, 2019 at 04:35 PM 0
Share

I don't think the Grid class should be a scriptableobject if you are not creating assets of it. I think they need to be explicitly saved as assets.

The data class can still use the array approach. You can just Serialize the grid class (if it is just holding basic data). Then you can add them to the data class manually.

 [System.Serializable]
 public class Grid
 {
     public string dataPoint1;
     public int dataPoint2;
     public float dataPoint3;
 }


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

108 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 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

Scriptable Object's Data Gets Lost After Re-opening Unity!!! 1 Answer

BinaryFormatter - saving and loading a list containing sprites. 0 Answers

ScriptableObject loses data after Reload 1 Answer

Unable to serialize my list in a Unity Custom Editor script. 1 Answer

Difference between assigning a value in inspector and with a custom editor script 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