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 Woj_Gabel_FertileSky · Oct 26, 2012 at 02:47 PM · saveserializecustom classrecompile

Serialize array of custom class in custom class

Hi! I have a problem with my custom class not saving after closing unity/recompiling.

 public class HeadClass {
   var eyes : Eye[,];
 
 }
 
 public class Eye {
   var m : Layers[]; 
 }
 
 public class Layers{
   var listOfLayers : List<GameObject>;
 }

Now, inside a script, the HeadClass class is saved:

 @SerializeField
 var allHeads : List.<HeadClass>;

But the remaining classes inside the HeadClass are not. I think they are not beeing serialized, but I dont know how to make this work. Can i serialize those classes somehow? EDIT: and i tried to use serialise (docs) on my custom class, but that also doesn't work:

 @script Serializable
 public class Eye {
   var m : Layers[]; 
 }

gives me an error.

Comment
Add comment · Show 2
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 spiceboy9994 · Oct 26, 2012 at 11:24 PM 1
Share

Won't reply this as answer but as comment, since you are using Javascript and I do C#, but this is how I do it:

[System.Serializable] public class Conversation { public int ConversationId; public string[] $$anonymous$$essages; public bool AlreadyDisplayed = false; }

public class NPCBehavior : $$anonymous$$onoBehaviour { public List Conversations; }

Not sure what is the syntax for Javascript. I don't have to mark any property as Serializable, since whole class Is marked like that. If you want, you can "hide" properties from serialize with [System.NonSerialized] (again C#), but in this case, I'm serializing all the props.

Hope this helps

avatar image Woj_Gabel_FertileSky · Nov 01, 2012 at 09:50 AM 0
Share

Hey spiceboy, thanks for info. I checked unity docs, and the [serialize] command, but cant use it in unityscript with syntax mentioned in those docs. Every time I try to serialize the main class the Eye class resets and is empty. Did a workaround: repopulate array after every recompile. It's a pain but it works.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hvilela · Oct 26, 2012 at 11:17 PM

To the class Eye be serialized, all this properties also need to be serializable and Layers are not.

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 Woj_Gabel_FertileSky · Nov 01, 2012 at 09:52 AM 0
Share

yes, but how can I serialize the Eye class? Unity docs syntax doesn't work. Only way i can think of is to serialize the Eye class as a array of serializable type and use that array for later repopulation. But it is a mess.

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

11 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

Related Questions

Serialization of custom class 1 Answer

How can I serialize the Particles of a Particle Emitter 1 Answer

Transferring gameobjects between projects 0 Answers

[SOLVED] Save System with Serialize multiple objects 2 Answers

UnitySerializer not saving properly/any longer 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