• 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
Question by Benjames · Mar 28, 2017 at 07:23 PM · editoreditor-scriptinglistssave datalist of lists

Retain values of a List of list of a class in editor?

Run down of what I am doing: Using scene view in editor to modify marching cubes set.

My problem is: the values in a List i am using for the marching cubes grid are not being retained in the scene. So when I save/close then reload the List is empty and null.

My List looks something like this..

 public class RoomCubes : MonoBehaviour
 {
     public List<List<List<voxel>>> vox;
 }
 
 public class voxel{
     public bool check;
     public bool mark;
 }




Comment
FlyingHighUp

People who like this

1 Show 0
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

  • Sort: 
avatar image
Best Answer

Answer by FlyingHighUp · Mar 28, 2017 at 08:26 PM

Unfortunately lists of lists are not serialized (and therefore not saved) by Unity. A hacky, but working solution is to define a class for each dimension of your array.

E.g.

  public class RoomCubes : MonoBehaviour
  {
 [SerializeField]
 List<VoxelD1> voxels;

 [System.Serializable]
 class VoxelD1
 {
       List<VoxelD2> voxels;
 }
 
 [System.Serializable]
 class VoxelD2
 {
       List<Voxel> voxels;
 }

 [System.Serializable]
 public class Voxel
 {
      public bool check;
      public bool mark;
  }
  }

Then, to get the element at 1,1,1

  voxels[1].voxels[1].voxels[1]

Which is pretty ugly. You could write a method

 List<List<List<voxel>>> generateListRepresentation();

to generate your previous format for ease of use.

Comment
Benjames
dvandamme

People who like this

2 Show 1 · 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 Benjames · Mar 29, 2017 at 03:10 PM 0
Share

So I changed it to array instead of a list and made a class for each dimension like you suggested. It works! Thank you.

I don't know if its in my head or not but it seems slower. It's because the editor is updating? alt text

[edit] I suppose it should of been obvious that a large array would slow down the editor. I made a child object that is there only to hold the array. If I happen to click the child object my computer practically freezes with a 40x40x40 array. But alas if I leave it alone editing the marching cubes is pretty quick.

untitled.jpg (166.1 kB)

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

83 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

Related Questions

CustomEditor not updating after changing a value? 0 Answers

Storing a list when application Quits 0 Answers

EditorWindow loses Texture2D reference on scene change: how to handle? 4 Answers

Drawing texture/sprite in editor view in world space 0 Answers

Cant override built in default inspectors anymore (transform, rigidbody etc) 0 Answers


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