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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by King Phoenix W. · Oct 27, 2014 at 05:37 AM · serializationserializedobject

Serializable class doesn't store list<>

Hi everyone, I have a problem, that I can't store the list "distances" inside my serializable class. The UnityEditor "forgets" it after a cycle. The class RAYpoint on the other hand is stored ,therefore I can get x,y,z. Guess its a problem with list in general. I tried some solutions offered by other users, sadly so far, I didn't get it to work. Hope someone can point me in the right direction. Cheers

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 [System.Serializable]
 public class RAYpoint{
 
     public RAYpoint(Vector3 vec) { vector = vec; }
     public Vector3 vector;
     public bool updated = false;
 
     [SerializeField]
     public List<_DistancePoint> distances = new List<_DistancePoint>();
     public RAYpoint[] neighbors = new RAYpoint[0];
 
     public void reset(){
         distances = new List<_DistancePoint>();
         neighbors = new RAYpoint[0];
     }
     
     public RAYpoint[] GetNeighbors(){
 
         if (!updated) {
 
             SortDistance ();
 
             neighbors = new RAYpoint[distances.Count];
 
             for(int i = 0; i < distances.Count; i++){
                 neighbors[i] = distances[i].point;
             }
         }
         
         return neighbors;
     }
 
     public void AddDistance(float distance, RAYpoint point){
         updated = false;
         
         if (distances == null) {
             distances = new List<_DistancePoint>();
         }
         
         distances.Add (new _DistancePoint (distance, point));
     }
 
     
     public void SortDistance(){
         if (!updated) {
             distances.Sort(
                 delegate(_DistancePoint p1, _DistancePoint p2) {
                 return p1.distance.CompareTo (p2.distance);
             });
         }
         updated = true;
     }
 
     public float x {
         get {
             return vector.x;
         }
         set
         {
             vector = new Vector3(value, vector.y, vector.z);
         }
     }
     
     public float y {
         get {
             return vector.y;
         }
         set
         {
             vector = new Vector3(vector.x, value , vector.z);
         }
     }
     
     public float z {
         get {
             return vector.z;
         }
         set
         {
             vector = new Vector3(vector.x, vector.y, value);
         }
     }
 
     
     public static implicit operator Vector3(RAYpoint obj){
         return obj.vector;
     }
     //  User-defined conversion from double to Digit
     public static implicit operator RAYpoint(Vector3 vector){
         return new RAYpoint(vector);
     }
     
     public override string ToString(){
         return vector.ToString();
     }
 
     /**************************************/
     [System.Serializable]
     public class _DistancePoint{
         
         public float distance { get; set; }
         public RAYpoint point { get; set; }
         
         public _DistancePoint(float distance, RAYpoint point){
             
             this.distance = distance;
             this.point = point;
         }
         
         public override string ToString(){
             return "Distance: " + distance + "   Point: " + point;
         }
     }
 
 }
 

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 frarees · Oct 27, 2014 at 02:39 PM

Make sure the _DistancePoint class is marked with System.Serializable, and the fields are serializable by Unity as well.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Assets Returning Null 0 Answers

ScriptableObject with Custom Editor resetting data in inspector 1 Answer

How to Serialize and Deserialize a Dictionary Containing Gameobject and a Vector 0 Answers

Error when trying to Serialize a field that is in a class 0 Answers

PropertyDrawer and EditorWindow 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