Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Steven-1 · Nov 12, 2013 at 03:14 PM · editorlistdata

How to store data in an object in a scene (in the editor)

I made a custom class which I assign to a gameobject, it has a couple of parameters, one of them of type List < List < Transform > >. Now the problem is that it seems to lose this data as soon as I reload the scene. whereas a List < Transform > still contains all its data.

also, all parameters are shown in the inspector, including the List < Transform >, only not the List < List < Transform > >.

Is this by design? How do I avoid this?

Comment
Add comment · Show 4
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 zombience · Nov 12, 2013 at 03:36 PM 0
Share

it can depend on what type you're storing in your list. for example, I ran into a problem some time ago where I was attempting to store a List of System.Type. Unity won't serialize System.Type, so I would always lose my stored list.

Another workaround is to create a custom class that stores your information, and have it inherit from ScriptableObject

avatar image Steven-1 · Nov 12, 2013 at 03:39 PM 0
Share

I actually typed what type of list it was, but apparently anything between gets deleted automatically. I'll fix my post. The type that doesn't get remembered is List < List >

avatar image zombience · Nov 12, 2013 at 03:40 PM 0
Share

make sure you hit the code button. adding characters like "

avatar image Steven-1 · Nov 12, 2013 at 03:41 PM 0
Share

ok, I just fixed it, but for some reason it still shows the previous version? edit: fixed again. I added spaces because it still gets removed otherwise, even when within code tags

1 Reply

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

Answer by zombience · Nov 12, 2013 at 03:34 PM

Newer Answer

I don't believe that Unity will serialize a two dimensional list. You can create a small serializable class that only contains a list of transforms. then you have a list of classes that each contain a list of transforms.

 public class ClassA : MonoBehaviour 
 {
 
     public List<TransformContainer> containers;
 
     void Start () 
     {
     
     }
 
     void Update () 
     {
     
     }
 }
 
 [System.Serializable]
 public class TransformContainer
 {
     public List<Transform> transforms;
 }

Original Answer It depends on what datatype your list is storing. You can store classes in your list and have them serialize, or object references. also, you need to make sure the list is public.

If you are storing custom classes, try this:

 [System.Serializable]
 public class ClassToStore
 {
     public int ID;
     public string name;
 }
 
 
 public class StorageClass : MonoBehaviour
 {
     public List<ClassToStore> storage;
 
     void Start()
     {
         // check storage in some way 
     }
 }

code test

 public List<List<Transform>> transforms;

works for me.

Comment
Add comment · Show 6 · 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 Steven-1 · Nov 12, 2013 at 03:46 PM 0
Share

UnityAnswers stupidly messed up my text, I edited it now so it makes more sence. The problem is it doesn't seem to remmber anything of type List < List >

avatar image zombience · Nov 12, 2013 at 03:50 PM 0
Share

you need to hit the "code" button in order to put in code, otherwise the webpage will misinterpret your code as HT$$anonymous$$L tags.

check this image:

http://imgur.com/AHnfVkO

avatar image zombience · Nov 12, 2013 at 03:53 PM 0
Share

also, I don't believe Unity can serialize two dimensional lists. You're trying to store a list of lists of transforms. If you really need that data structure, then I would make a very small class that only has a List of transforms. I'll update my answer above

avatar image Steven-1 · Nov 12, 2013 at 03:56 PM 0
Share

I know, I did, it was still messed up.

avatar image zombience · Nov 12, 2013 at 03:59 PM 0
Share
 public List<List<Transform>> transforms

works for me

Show more comments

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

17 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

Related Questions

A node in a childnode? 1 Answer

Trying to have my Editor Script save the changed settings when I hit Play 0 Answers

Save and Load Function 2 Answers

Update List<> in editor 0 Answers

How can I assign an Array of Vector3 while seeing and editing the values in the Scene? 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