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
1
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
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
2
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
Add comment · 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 ins$$anonymous$$d 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)

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

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

Storing a list when application Quits 0 Answers

CustomEditor not updating after changing a value? 0 Answers

applying toon shading to all 3d meshes at once 1 Answer

Drop down selection list 1 Answer

Show/hide wireframe for the current selected object? 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