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 silverdreamx · Nov 07, 2012 at 02:47 PM · editorinspectorserialization

Serializing list of base and derived classes with custom inspector

Hi everyone!

I have a problem trying to save an array of a list of custom base and derived classes. I have tried to follow the Serialization Megapost but I am still unable to save the data within the array of lists.

GameConfigManager:

 public class GameConfigManager : MonoBehaviour
 {
     public MultidimensionalCategoryGame[] categoryGameList;
     public int playsToUnlock;
 }



MultidimensionalCategoryGame.cs

 [System.Serializable]
 public class MultidimensionalCategoryGame : ScriptableObject
 {
     [SerializeField]
     public List<Powerup> array;
     
     public void OnEnable()
     {
         hideFlags = HideFlags.HideAndDontSave;
         if (array == null)
         {
             array = new List<Powerup>();
         }
     }
 }



CategoryGame.cs

 [System.Serializable]
 public class CategoryGame : Powerup
 {
     public int discount;
     public string[] instructions;
     
     public override void OnEnable()
     {
         base.OnEnable();
         
         if (instructions == null)
         {
             discount = 0;
             instructions = new string[0];
         }
     }
 }



Powerup.cs

 [System.Serializable]
 public class Powerup : ScriptableObject
 {
     public string name;
     public string description;
     public float cost;
     
     public virtual void OnEnable()
     {
         hideFlags = HideFlags.HideAndDontSave;
         
         if (name == null)
         {
             name = "";
             description = "";
             cost = 0;
         }
     }

From my testing, I can save the integer playsToUnlock variable within GameConfigManager. I can also enter data for the MultidimensionalCategoryGame objects in the inspector, but when I hit play my data within MultidimensionalCategoryGame objects are not saved.

Sorry for the long post! Thanks for your time and please help!!!

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
1
Best Answer

Answer by cygnusfear · Nov 07, 2012 at 03:22 PM

Not sure if this is going to help you out; but Jacob Pennock wrote a nice post on how to create custom assets.

This will provide you with the means to do offline editing on your powerup and drag that powerup straight into your inspector.

http://www.jacobpennock.com/Blog/?p=670

If this doesn't help out, let me know and I'll dig a bit deeper into your code

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 silverdreamx · Nov 08, 2012 at 05:01 AM 0
Share

Thanks cygnusfear! This post helped me find the solution with some tweaking on the inspector side!!!

For those that had the same problem as I did, I had to reorganize my data structure to avoid editing arrays of lists within the same class. Originally I was trying to edit the Powerups/CategoryGame data in the GameConfig$$anonymous$$anager, but now I save the $$anonymous$$ultidimensionalCategoryGame as an asset file (i followed the link cygnusfear posted above to do so), and then assign each $$anonymous$$ultidimensionalCategoryGame asset into the list in my GameConfig$$anonymous$$anager.

Hope this helps anyone who had the same problem as I did!

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

Why can't a MonoBehaviour subtype with generic arguments be serialized in a list since Unity 4.5? 0 Answers

Populating list of custom class through inspector 1 Answer

Saving editor-only variables 0 Answers

Dictionary in inspector 4 Answers

Showing properties from a base class in inspector? 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